Commit 399a570f authored by Tom Lane's avatar Tom Lane

int8in failed to detect overflow; it really should.

parent f40c5062
...@@ -59,8 +59,7 @@ int8in(char *str) ...@@ -59,8 +59,7 @@ int8in(char *str)
/* /*
* Do our own scan, rather than relying on sscanf which might be * Do our own scan, rather than relying on sscanf which might be
* broken for long long. NOTE: this will not detect int64 overflow... * broken for long long.
* but sscanf doesn't either...
*/ */
while (*ptr && isspace(*ptr)) /* skip leading spaces */ while (*ptr && isspace(*ptr)) /* skip leading spaces */
ptr++; ptr++;
...@@ -69,11 +68,17 @@ int8in(char *str) ...@@ -69,11 +68,17 @@ int8in(char *str)
else if (*ptr == '+') else if (*ptr == '+')
ptr++; ptr++;
if (!isdigit(*ptr)) /* require at least one digit */ if (!isdigit(*ptr)) /* require at least one digit */
elog(ERROR, "Bad int8 external representation '%s'", str); elog(ERROR, "Bad int8 external representation \"%s\"", str);
while (*ptr && isdigit(*ptr)) /* process digits */ while (*ptr && isdigit(*ptr)) /* process digits */
tmp = tmp * 10 + (*ptr++ - '0'); {
int64 newtmp = tmp * 10 + (*ptr++ - '0');
if ((newtmp / 10) != tmp) /* overflow? */
elog(ERROR,"int8 value out of range: \"%s\"", str);
tmp = newtmp;
}
if (*ptr) /* trailing junk? */ if (*ptr) /* trailing junk? */
elog(ERROR, "Bad int8 external representation '%s'", str); elog(ERROR, "Bad int8 external representation \"%s\"", str);
*result = (sign < 0) ? -tmp : tmp; *result = (sign < 0) ? -tmp : tmp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment