diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-30 23:10:34 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-30 23:10:34 +0000 |
commit | a4a51d58e81fd1b9d861f645cfcf3e6778004949 (patch) | |
tree | a689115daa3e708fbfb9092a7ba6f8ac32ea5269 /src/backend/utils/adt/numutils.c | |
parent | f9bdaeeb346065fe45b8761217c869c80e1c89b4 (diff) | |
download | postgresql-a4a51d58e81fd1b9d861f645cfcf3e6778004949.tar.gz postgresql-a4a51d58e81fd1b9d861f645cfcf3e6778004949.zip |
Rearrange code in pg_atoi() to avoid assuming that isspace() cannot
change errno. No reported bugs here, but why take a chance?
Diffstat (limited to 'src/backend/utils/adt/numutils.c')
-rw-r--r-- | src/backend/utils/adt/numutils.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index fb7fd94b8c8..c75bf517e02 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -10,13 +10,12 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.68 2005/01/09 21:03:19 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.68.4.1 2005/11/30 23:10:34 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" -#include <errno.h> #include <math.h> #include <limits.h> #include <ctype.h> @@ -84,19 +83,6 @@ pg_atoi(char *s, int size, int c) errmsg("invalid input syntax for integer: \"%s\"", s))); - /* - * Skip any trailing whitespace; if anything but whitespace remains - * before the terminating character, bail out - */ - while (*badp && *badp != c && isspace((unsigned char) *badp)) - badp++; - - if (*badp && *badp != c) - ereport(ERROR, - (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for integer: \"%s\"", - s))); - switch (size) { case sizeof(int32): @@ -125,6 +111,20 @@ pg_atoi(char *s, int size, int c) default: elog(ERROR, "unsupported result size: %d", size); } + + /* + * Skip any trailing whitespace; if anything but whitespace remains + * before the terminating character, bail out + */ + while (*badp && *badp != c && isspace((unsigned char) *badp)) + badp++; + + if (*badp && *badp != c) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for integer: \"%s\"", + s))); + return (int32) l; } |