summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-03-22 17:41:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-03-22 17:41:47 +0000
commitb32cac8055118d264b27b1073d3d43e9a127130e (patch)
tree1d9f228f94653c7cf7d1485163428bef1ba52390 /src/backend/parser
parent339cd6b9b00451f1f7046d6b52500e2d2992a385 (diff)
Fix Joubert's complaint that int8-sized numeric literals are mishandled
on Alpha (because parser mistakenly assumes that a nonoverflow result from strtol means the value will fit into int4). A scan for other uses of 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 to avoid complaints from compilers that think x != x is a silly test (cf. pg_atoi).
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/scan.l24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index f913584c1a7..0f876e7718c 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.87 2001/02/21 18:53:47 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.88 2001/03/22 17:41:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -310,14 +310,21 @@ other .
startlit();
}
<xh>{xhstop} {
+ long val;
char* endptr;
BEGIN(INITIAL);
errno = 0;
- yylval.ival = strtol(literalbuf, &endptr, 16);
- if (*endptr != '\0' || errno == ERANGE)
+ val = strtol(literalbuf, &endptr, 16);
+ if (*endptr != '\0' || errno == ERANGE
+#ifdef HAVE_LONG_INT_64
+ /* if long > 32 bits, check for overflow of int4 */
+ || val != (long) ((int32) val)
+#endif
+ )
elog(ERROR, "Bad hexadecimal integer input '%s'",
literalbuf);
+ yylval.ival = val;
return ICONST;
}
<xh><<EOF>> { elog(ERROR, "Unterminated hexadecimal integer"); }
@@ -454,16 +461,23 @@ other .
}
{integer} {
+ long val;
char* endptr;
errno = 0;
- yylval.ival = strtol((char *)yytext, &endptr, 10);
- if (*endptr != '\0' || errno == ERANGE)
+ val = strtol((char *)yytext, &endptr, 10);
+ if (*endptr != '\0' || errno == ERANGE
+#ifdef HAVE_LONG_INT_64
+ /* if long > 32 bits, check for overflow of int4 */
+ || val != (long) ((int32) val)
+#endif
+ )
{
/* integer too large, treat it as a float */
yylval.str = pstrdup((char*)yytext);
return FCONST;
}
+ yylval.ival = val;
return ICONST;
}
{decimal} {