Skip to content

Commit 164442f

Browse files
committed
Rearrange code in pg_atoi() to avoid assuming that isspace() cannot
change errno. No reported bugs here, but why take a chance?
1 parent bae3fef commit 164442f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/backend/utils/adt/numutils.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.69 2005/10/15 02:49:29 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.70 2005/11/30 23:10:08 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
1717
#include "postgres.h"
1818

19-
#include <errno.h>
2019
#include <math.h>
2120
#include <limits.h>
2221
#include <ctype.h>
@@ -84,19 +83,6 @@ pg_atoi(char *s, int size, int c)
8483
errmsg("invalid input syntax for integer: \"%s\"",
8584
s)));
8685

87-
/*
88-
* Skip any trailing whitespace; if anything but whitespace remains before
89-
* the terminating character, bail out
90-
*/
91-
while (*badp && *badp != c && isspace((unsigned char) *badp))
92-
badp++;
93-
94-
if (*badp && *badp != c)
95-
ereport(ERROR,
96-
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
97-
errmsg("invalid input syntax for integer: \"%s\"",
98-
s)));
99-
10086
switch (size)
10187
{
10288
case sizeof(int32):
@@ -125,6 +111,20 @@ pg_atoi(char *s, int size, int c)
125111
default:
126112
elog(ERROR, "unsupported result size: %d", size);
127113
}
114+
115+
/*
116+
* Skip any trailing whitespace; if anything but whitespace remains before
117+
* the terminating character, bail out
118+
*/
119+
while (*badp && *badp != c && isspace((unsigned char) *badp))
120+
badp++;
121+
122+
if (*badp && *badp != c)
123+
ereport(ERROR,
124+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
125+
errmsg("invalid input syntax for integer: \"%s\"",
126+
s)));
127+
128128
return (int32) l;
129129
}
130130

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy