Commit ba826299 authored by Tom Lane's avatar Tom Lane

Allow trailing whitespace in parse_real(), for consistency with

parse_int() and with itself (strtod allows leading whitespace, so it
seems odd not to allow trailing whitespace).  parse_bool remains
not-whitespace-friendly, but this is generically true for non-numeric
GUC variables, so I'll desist from changing it.
parent aa55d055
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.401 2007/06/21 18:14:21 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.402 2007/06/21 22:59:12 tgl Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -3721,9 +3721,9 @@ ReportGUCOption(struct config_generic * record) ...@@ -3721,9 +3721,9 @@ ReportGUCOption(struct config_generic * record)
/* /*
* Try to interpret value as boolean value. Valid values are: true, * Try to interpret value as boolean value. Valid values are: true,
* false, yes, no, on, off, 1, 0. If the string parses okay, return * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
* true, else false. If result is not NULL, return the parsing result * If the string parses okay, return true, else false.
* there. * If okay and result is not NULL, return the value in *result.
*/ */
static bool static bool
parse_bool(const char *value, bool *result) parse_bool(const char *value, bool *result)
...@@ -3999,9 +3999,9 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg) ...@@ -3999,9 +3999,9 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
/* /*
* Try to parse value as a floating point constant in the usual * Try to parse value as a floating point number in the usual format.
* format. If the value parsed okay return true, else false. If * If the string parses okay, return true, else false.
* result is not NULL, return the semantic value there. * If okay and result is not NULL, return the value in *result.
*/ */
static bool static bool
parse_real(const char *value, double *result) parse_real(const char *value, double *result)
...@@ -4009,14 +4009,20 @@ parse_real(const char *value, double *result) ...@@ -4009,14 +4009,20 @@ parse_real(const char *value, double *result)
double val; double val;
char *endptr; char *endptr;
if (result)
*result = 0; /* suppress compiler warning */
errno = 0; errno = 0;
val = strtod(value, &endptr); val = strtod(value, &endptr);
if (endptr == value || *endptr != '\0' || errno == ERANGE) if (endptr == value || errno == ERANGE)
{
if (result)
*result = 0; /* suppress compiler warning */
return false; return false;
}
/* allow whitespace after number */
while (isspace((unsigned char) *endptr))
endptr++;
if (*endptr != '\0')
return false;
if (result) if (result)
*result = val; *result = val;
return true; return true;
......
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