aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-30 23:10:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-30 23:10:08 +0000
commit164442fe7f7440b6a004e51bc19d990cb89b4abd (patch)
tree8c1d9e631475076e9b2fc5aa7d74b0caeae575a3 /src
parentbae3fefd4aecec5cbe94c1d67804f6ba7df0a203 (diff)
downloadpostgresql-164442fe7f7440b6a004e51bc19d990cb89b4abd.tar.gz
postgresql-164442fe7f7440b6a004e51bc19d990cb89b4abd.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')
-rw-r--r--src/backend/utils/adt/numutils.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c
index ffa225277e1..994e30b51a3 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.69 2005/10/15 02:49:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.70 2005/11/30 23:10:08 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;
}