Commit 521e8888 authored by Tom Lane's avatar Tom Lane

Undo an unadvertised change in the API of pg_atoi. In all previous

releases, a nonzero 'c' argument meant that the input string could be
terminated by either that character or \0.  Recent refactoring broke
that, causing the thing to scan for 'c' only.  This went undetected
because no part of the main code actually passes nonzero 'c'.  However
it broke tsearch2 and possibly other user-written code that assumed
the old definition.  Per report from Tom Hebbron.
parent 0471cd5f
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.67 2004/12/31 22:01:22 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.68 2005/01/09 21:03:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,12 +46,12 @@ ...@@ -46,12 +46,12 @@
/* /*
* pg_atoi: convert string to integer * pg_atoi: convert string to integer
* *
* 'size' is the sizeof() the desired integral result (1, 2, or 4 bytes).
*
* allows any number of leading or trailing whitespace characters. * allows any number of leading or trailing whitespace characters.
* *
* 'c' is the character that terminates the input string (after any * 'size' is the sizeof() the desired integral result (1, 2, or 4 bytes).
* number of whitespace characters). *
* c, if not 0, is a terminator character that may appear after the
* integer (plus whitespace). If 0, the string must end after the integer.
* *
* Unlike plain atoi(), this will throw ereport() upon bad input format or * Unlike plain atoi(), this will throw ereport() upon bad input format or
* overflow. * overflow.
...@@ -88,10 +88,10 @@ pg_atoi(char *s, int size, int c) ...@@ -88,10 +88,10 @@ pg_atoi(char *s, int size, int c)
* Skip any trailing whitespace; if anything but whitespace remains * Skip any trailing whitespace; if anything but whitespace remains
* before the terminating character, bail out * before the terminating character, bail out
*/ */
while (*badp != c && isspace((unsigned char) *badp)) while (*badp && *badp != c && isspace((unsigned char) *badp))
badp++; badp++;
if (*badp != c) if (*badp && *badp != c)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"", errmsg("invalid input syntax for integer: \"%s\"",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment