Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb32cac8

Browse files
committed
Fix Joubert's complaint that int8-sized numeric literals are mishandled
on Alpha (because parser mistakenly assumes that a nonoverflow resultfrom strtol means the value will fit into int4). A scan for other usesof strtol and strtoul found a couple other places with the same mistake;fix them too. The changes are all conditional on HAVE_LONG_INT_64 toavoid complaints from compilers that think x != x is a silly test(cf. pg_atoi).
1 parent339cd6b commitb32cac8

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

‎src/backend/nodes/read.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/nodes/read.c,v 1.29 2001/03/2203:59:32 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/nodes/read.c,v 1.30 2001/03/2217:41:47 tgl Exp $
1313
*
1414
* HISTORY
1515
* AUTHORDATEMAJOR EVENT
@@ -203,7 +203,6 @@ nodeTokenType(char *token, int length)
203203
NodeTagretval;
204204
char*numptr;
205205
intnumlen;
206-
char*endptr;
207206

208207
/*
209208
* Check if the token is a number
@@ -215,16 +214,23 @@ nodeTokenType(char *token, int length)
215214
if ((numlen>0&&isdigit((unsignedchar)*numptr))||
216215
(numlen>1&&*numptr=='.'&&isdigit((unsignedchar)numptr[1])))
217216
{
218-
219217
/*
220218
* Yes. Figure out whether it is integral or float; this requires
221219
* both a syntax check and a range check. strtol() can do both for
222220
* us. We know the token will end at a character that strtol will
223221
* stop at, so we do not need to modify the string.
224222
*/
223+
longval;
224+
char*endptr;
225+
225226
errno=0;
226-
(void)strtol(token,&endptr,10);
227-
if (endptr!=token+length||errno==ERANGE)
227+
val=strtol(token,&endptr,10);
228+
if (endptr!=token+length||errno==ERANGE
229+
#ifdefHAVE_LONG_INT_64
230+
/* if long > 32 bits, check for overflow of int4 */
231+
||val!= (long) ((int32)val)
232+
#endif
233+
)
228234
returnT_Float;
229235
returnT_Integer;
230236
}

‎src/backend/parser/scan.l

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.87 2001/02/21 18:53:47 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.88 2001/03/22 17:41:47 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -310,14 +310,21 @@ other.
310310
startlit();
311311
}
312312
<xh>{xhstop}{
313+
long val;
313314
char* endptr;
314315

315316
BEGIN(INITIAL);
316317
errno =0;
317-
yylval.ival =strtol(literalbuf, &endptr,16);
318-
if (*endptr !='\0' || errno == ERANGE)
318+
val =strtol(literalbuf, &endptr,16);
319+
if (*endptr !='\0' || errno == ERANGE
320+
#ifdef HAVE_LONG_INT_64
321+
/* if long > 32 bits, check for overflow of int4 */
322+
|| val != (long) ((int32) val)
323+
#endif
324+
)
319325
elog(ERROR,"Bad hexadecimal integer input '%s'",
320326
literalbuf);
327+
yylval.ival = val;
321328
return ICONST;
322329
}
323330
<xh><<EOF>>{elog(ERROR,"Unterminated hexadecimal integer"); }
@@ -454,16 +461,23 @@ other.
454461
}
455462

456463
{integer}{
464+
long val;
457465
char* endptr;
458466

459467
errno =0;
460-
yylval.ival =strtol((char *)yytext, &endptr,10);
461-
if (*endptr !='\0' || errno == ERANGE)
468+
val =strtol((char *)yytext, &endptr,10);
469+
if (*endptr !='\0' || errno == ERANGE
470+
#ifdef HAVE_LONG_INT_64
471+
/* if long > 32 bits, check for overflow of int4 */
472+
|| val != (long) ((int32) val)
473+
#endif
474+
)
462475
{
463476
/* integer too large, treat it as a float */
464477
yylval.str =pstrdup((char*)yytext);
465478
return FCONST;
466479
}
480+
yylval.ival = val;
467481
return ICONST;
468482
}
469483
{decimal}{

‎src/backend/utils/misc/guc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.34 2001/03/2204:00:06 momjian Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.35 2001/03/2217:41:47 tgl Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -520,7 +520,12 @@ parse_int(const char *value, int *result)
520520

521521
errno=0;
522522
val=strtol(value,&endptr,0);
523-
if (endptr==value||*endptr!='\0'||errno==ERANGE)
523+
if (endptr==value||*endptr!='\0'||errno==ERANGE
524+
#ifdefHAVE_LONG_INT_64
525+
/* if long > 32 bits, check for overflow of int4 */
526+
||val!= (long) ((int32)val)
527+
#endif
528+
)
524529
return false;
525530
if (result)
526531
*result= (int)val;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp