]> granicus.if.org Git - postgresql/commitdiff
Fix uninitialized-variable warning.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 25 Nov 2014 20:16:49 +0000 (15:16 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 25 Nov 2014 20:17:16 +0000 (15:17 -0500)
In passing, add an Assert defending the presumption that bytes_left
is positive to start with.  (I'm not exactly convinced that using an
unsigned type was such a bright thing here, but let's at least do
this much.)

src/backend/utils/misc/guc.c

index f04757c5826218fd167ad06a2a8494b181b09084..6b4db305e58d65a11c1f3d07ddf840bfc312de4c 100644 (file)
@@ -8741,9 +8741,10 @@ SerializeGUCState(Size maxsize, char *start_address)
        Size            actual_size;
        Size            bytes_left;
        int                     i;
-       int                     i_role;
+       int                     i_role = -1;
 
        /* Reserve space for saving the actual size of the guc state */
+       Assert(maxsize > sizeof(actual_size));
        curptr = start_address + sizeof(actual_size);
        bytes_left = maxsize - sizeof(actual_size);
 
@@ -8759,7 +8760,8 @@ SerializeGUCState(Size maxsize, char *start_address)
                else
                        serialize_variable(&curptr, &bytes_left, guc_variables[i]);
        }
-       serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
+       if (i_role >= 0)
+               serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
 
        /* Store actual size without assuming alignment of start_address. */
        actual_size = maxsize - bytes_left - sizeof(actual_size);