Skip to content

Commit 84e5ce7

Browse files
committed
Back-patch into 7.2 branch the 7.3 changes that made contrib/seg
error messages reasonably independent of the bison version used to build segparse.c. Needed to get this branch passing on buildfarm.
1 parent 44e7a2a commit 84e5ce7

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

contrib/seg/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Header: /cvsroot/pgsql/contrib/seg/Makefile,v 1.6 2001/11/16 16:32:33 petere Exp $
1+
# $Header: /cvsroot/pgsql/contrib/seg/Makefile,v 1.6.2.1 2005/07/16 19:48:15 tgl Exp $
22

33
subdir = contrib/seg
44
top_builddir = ../..
@@ -13,11 +13,17 @@ REGRESS = seg
1313

1414
segparse.c: segparse.h ;
1515

16+
# The sed hack is so that we can get the same error messages with
17+
# bison 1.875 and later as we did with earlier bisons. Eventually,
18+
# I suppose, we should re-standardize on "syntax error" --- in which
19+
# case flip the sed translation, but don't remove it.
20+
1621
segparse.h: segparse.y
1722
ifdef YACC
1823
$(YACC) -d $(YFLAGS) -p seg_yy $<
19-
mv -f y.tab.c segparse.c
24+
sed -e 's/"syntax error/"parse error/' < y.tab.c > segparse.c
2025
mv -f y.tab.h segparse.h
26+
rm -f y.tab.c
2127
else
2228
@$(missing) bison $< $@
2329
endif

contrib/seg/expected/seg.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,25 @@ SELECT '100(+-)1'::seg AS seg;
393393
SELECT ''::seg AS seg;
394394
ERROR: seg_in: can't parse an empty string
395395
SELECT 'ABC'::seg AS seg;
396-
ERROR: parse error, expecting `FLOAT' or `RANGE' or `EXTENSION' at or near position 1, character ('A', \101), input: 'ABC'
396+
ERROR: parse error at or near position 1, character ('A', \101), input: 'ABC'
397397

398398
SELECT '1ABC'::seg AS seg;
399-
ERROR: expecting end of input at or near position 2, character ('A', \101), input: '1ABC'
399+
ERROR: parse error at or near position 2, character ('A', \101), input: '1ABC'
400400

401401
SELECT '1.'::seg AS seg;
402-
ERROR: expecting end of input at or near position 2, character ('.', \056), input: '1.'
402+
ERROR: parse error at or near position 2, character ('.', \056), input: '1.'
403403

404404
SELECT '1.....'::seg AS seg;
405-
ERROR: expecting end of input at or near position 6, character ('.', \056), input: '1.....'
405+
ERROR: parse error at or near position 6, character ('.', \056), input: '1.....'
406406

407407
SELECT '.1'::seg AS seg;
408-
ERROR: parse error, expecting `FLOAT' or `RANGE' or `EXTENSION' at or near position 2, character ('1', \061), input: '.1'
408+
ERROR: parse error at or near position 2, character ('1', \061), input: '.1'
409409

410410
SELECT '1..2.'::seg AS seg;
411-
ERROR: expecting end of input at or near position 5, character ('.', \056), input: '1..2.'
411+
ERROR: parse error at or near position 5, character ('.', \056), input: '1..2.'
412412

413413
SELECT '1 e7'::seg AS seg;
414-
ERROR: expecting end of input at or near position 3, character ('e', \145), input: '1 e7'
414+
ERROR: parse error at or near position 3, character ('e', \145), input: '1 e7'
415415

416416
SELECT '1e700'::seg AS seg;
417417
ERROR: numeric value 1e700 unrepresentable

contrib/seg/segparse.y

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
%{
2-
#define YYERROR_VERBOSE
32
#define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
43

5-
#include <string.h>
6-
#include <stdlib.h>
4+
#include "postgres.h"
5+
76
#include <errno.h>
87
#include <math.h>
8+
9+
#include "utils/elog.h"
10+
911
#include "segdata.h"
1012
#include "buffer.h"
1113

12-
#include "postgres.h"
13-
#include "utils/elog.h"
14-
1514
#ifdef __CYGWIN__
1615
#define HUGE HUGE_VAL
1716
#endif /* __CYGWIN__ */
@@ -147,9 +146,9 @@ float seg_atof ( char *value ) {
147146
sscanf(value, "%f", &result);
148147

149148
if ( errno ) {
150-
sprintf(buf, "numeric value %s unrepresentable", value);
149+
snprintf(buf, 256, "numeric value %s unrepresentable", value);
151150
reset_parse_buffer();
152-
elog(ERROR, buf);
151+
elog(ERROR, "%s", buf);
153152
}
154153

155154
return result;
@@ -168,8 +167,9 @@ int seg_yyerror ( char *msg ) {
168167

169168
position = parse_buffer_pos() > parse_buffer_size() ? parse_buffer_pos() - 1 : parse_buffer_pos();
170169

171-
sprintf(
170+
snprintf(
172171
buf,
172+
256,
173173
"%s at or near position %d, character ('%c', \\%03o), input: '%s'\n",
174174
msg,
175175
position,
@@ -179,7 +179,7 @@ int seg_yyerror ( char *msg ) {
179179
);
180180

181181
reset_parse_buffer();
182-
elog(ERROR, buf);
182+
elog(ERROR, "%s", buf);
183183
return 0;
184184
}
185185

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy