1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

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).
This commit is contained in:
Tom Lane
2001-03-22 17:41:47 +00:00
parent 339cd6b9b0
commit b32cac8055
3 changed files with 37 additions and 12 deletions

View File

@@ -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} {