Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit786b180

Browse files
committed
The pg_atoi() function uses strtol() to convert the string to numbers. Some
implementations of strtol() treat empty strings ("") as invalid argumentswhile others convert this (erroneously, IHMO) to zero (0). Assuming that theexpected behaviour of pg_atoi() is to return 0 if it is passed an emptystring, I am supplying the following patch to explictly check for an emptystring in pg_atoi() and return 0 if the string is empty. The patch will alsotrap a NULL character pointer being passed to pg_atoi() and will use elog() toprint out an error message if the input char pointer is NULL.Billy G. Allie
1 parent5f7fb67 commit786b180

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

‎src/backend/utils/adt/numutils.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.26 1998/09/0104:32:43 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.27 1998/09/12 16:04:35 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -55,8 +55,19 @@ pg_atoi(char *s, int size, int c)
5555

5656
Assert(s);
5757

58-
errno=0;
59-
l=strtol(s,&badp,10);
58+
errno=0;
59+
60+
/*
61+
* Some versions of strtol treat the empty string as an error. This
62+
* code will explicitly return 0 for an empty string.
63+
*/
64+
65+
if (s== (char*)NULL)
66+
elog(ERROR,"pg_atoi: NULL pointer!");
67+
elseif (*s==0)
68+
l= (long)0;
69+
else
70+
l=strtol(s,&badp,10);
6071
if (errno)/* strtol must set ERANGE */
6172
elog(ERROR,"pg_atoi: error reading \"%s\": %m",s);
6273
if (badp&&*badp&& (*badp!=c))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp