Fix minor bugs in commit 30bf4689a96cd283af33edcdd6b7210df3f20cd8 et al.
authorTom Lane <[email protected]>
Sun, 30 Nov 2014 17:20:44 +0000 (12:20 -0500)
committerTom Lane <[email protected]>
Sun, 30 Nov 2014 17:20:44 +0000 (12:20 -0500)
Coverity complained that the "else" added to fillPGconn() was unreachable,
which it was.  Remove the dead code.  In passing, rearrange the tests so as
not to bother trying to fetch values for options that can't be assigned.

Pre-9.3 did not have that issue, but it did have a "return" that should be
"goto oom_error" to ensure that a suitable error message gets filled in.

src/interfaces/libpq/fe-connect.c

index 3af222b5a0924acb3959bffb1af5a04c3edea94f..3bac2bcadbbd550e1d2ff3e7bca99fb811445f1e 100644 (file)
@@ -684,16 +684,16 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
 
    for (option = PQconninfoOptions; option->keyword; option++)
    {
-       const char *tmp = conninfo_getval(connOptions, option->keyword);
-
-       if (tmp && option->connofs >= 0)
+       if (option->connofs >= 0)
        {
-           char      **connmember = (char **) ((char *) conn + option->connofs);
+           const char *tmp = conninfo_getval(connOptions, option->keyword);
 
-           if (*connmember)
-               free(*connmember);
            if (tmp)
            {
+               char      **connmember = (char **) ((char *) conn + option->connofs);
+
+               if (*connmember)
+                   free(*connmember);
                *connmember = strdup(tmp);
                if (*connmember == NULL)
                {
@@ -702,8 +702,6 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
                    return false;
                }
            }
-           else
-               *connmember = NULL;
        }
    }
 
@@ -793,7 +791,6 @@ connectOptions2(PGconn *conn)
            conn->pgpass = strdup(DefaultPassword);
            if (!conn->pgpass)
                goto oom_error;
-
        }
        else
            conn->dot_pgpass_used = true;