Allow trailing whitespace in parse_real(), for consistency with
authorTom Lane
Thu, 21 Jun 2007 22:59:12 +0000 (22:59 +0000)
committerTom Lane
Thu, 21 Jun 2007 22:59:12 +0000 (22:59 +0000)
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.

src/backend/utils/misc/guc.c

index c0032fabad2c38ee0ffcdecfc3e4e576efd05e07..73402dec6a8e1b6a857b80ad75d98281c8fa0f7f 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut .
  *
  * 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)
 
 /*
  * Try to interpret value as boolean value.  Valid values are: true,
- * false, yes, no, on, off, 1, 0.  If the string parses okay, return
- * true, else false.  If result is not NULL, return the parsing result
- * there.
+ * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
+ * If the string parses okay, return true, else false.
+ * If okay and result is not NULL, return the value in *result.
  */
 static bool
 parse_bool(const char *value, bool *result)
@@ -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
- * format. If the value parsed okay return true, else false.  If
- * result is not NULL, return the semantic value there.
+ * Try to parse value as a floating point number in the usual format.
+ * If the string parses okay, return true, else false.
+ * If okay and result is not NULL, return the value in *result.
  */
 static bool
 parse_real(const char *value, double *result)
@@ -4009,14 +4009,20 @@ parse_real(const char *value, double *result)
    double      val;
    char       *endptr;
 
+   if (result)
+       *result = 0;            /* suppress compiler warning */
+
    errno = 0;
    val = strtod(value, &endptr);
-   if (endptr == value || *endptr != '\0' || errno == ERANGE)
-   {
-       if (result)
-           *result = 0;        /* suppress compiler warning */
+   if (endptr == value || errno == ERANGE)
        return false;
-   }
+
+   /* allow whitespace after number */
+   while (isspace((unsigned char) *endptr))
+       endptr++;
+   if (*endptr != '\0')
+       return false;
+
    if (result)
        *result = val;
    return true;