diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-02-24 01:54:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-02-24 01:54:40 +0000 |
commit | 399a570fe269d7a2773b7f975caad4003e781982 (patch) | |
tree | c39a12a92cb0ddb83cbeee99a929bb5fcb304f48 /src | |
parent | f40c50627f8df66b3a15a69cbe493ecbde78b8f2 (diff) | |
download | postgresql-399a570fe269d7a2773b7f975caad4003e781982.tar.gz postgresql-399a570fe269d7a2773b7f975caad4003e781982.zip |
int8in failed to detect overflow; it really should.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/int8.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 7b444df1857..7c00686b194 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -59,8 +59,7 @@ int8in(char *str) /* * Do our own scan, rather than relying on sscanf which might be - * broken for long long. NOTE: this will not detect int64 overflow... - * but sscanf doesn't either... + * broken for long long. */ while (*ptr && isspace(*ptr)) /* skip leading spaces */ ptr++; @@ -69,11 +68,17 @@ int8in(char *str) else if (*ptr == '+') ptr++; 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 */ - 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? */ - elog(ERROR, "Bad int8 external representation '%s'", str); + elog(ERROR, "Bad int8 external representation \"%s\"", str); *result = (sign < 0) ? -tmp : tmp; |