Fix thinkos from 4f4061b for libpq integer parsing
authorMichael Paquier <michael@paquier.xyz>
Wed, 23 Oct 2019 02:34:18 +0000 (11:34 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 23 Oct 2019 02:34:18 +0000 (11:34 +0900)
A check was redundant.  While on it, add an assertion to make sure that
the parsing routine is never called with a NULL input.  All the code
paths currently calling the parsing routine are careful with NULL inputs
already, but future callers may forget that.

Reported-by: Peter Eisentraut, Lars Kanis
Discussion: https://postgr.es/m/ec64956b-4597-56b6-c3db-457d15250fe4@2ndquadrant.com
Backpatch-through: 12

src/interfaces/libpq/fe-connect.c

index 9af830321c3b61f6eed01454d2fc4e236857aec8..99051231a6e0a43290c8b265a3cd13c948c1b266 100644 (file)
@@ -1696,6 +1696,8 @@ parse_int_param(const char *value, int *result, PGconn *conn,
    char       *end;
    long        numval;
 
+   Assert(value != NULL);
+
    *result = 0;
 
    /* strtol(3) skips leading whitespaces */
@@ -1713,10 +1715,10 @@ parse_int_param(const char *value, int *result, PGconn *conn,
     * Skip any trailing whitespace; if anything but whitespace remains before
     * the terminating character, fail
     */
-   while (*end && *end != '\0' && isspace((unsigned char) *end))
+   while (*end != '\0' && isspace((unsigned char) *end))
        end++;
 
-   if (*end && *end != '\0')
+   if (*end != '\0')
        goto error;
 
    *result = numval;