From: Tom Lane Date: Wed, 14 Feb 2018 21:06:49 +0000 (-0500) Subject: Silence assorted "variable may be used uninitialized" warnings. X-Git-Tag: REL_11_BETA1~780 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a725f7b5cb7e8c8894ef121b49eff9c265245c8;p=postgresql Silence assorted "variable may be used uninitialized" warnings. All of these are false positives, but in each case a fair amount of analysis is needed to see that, and it's not too surprising that not all compilers are smart enough. (In particular, in the logtape.c case, a compiler lacking the knowledge provided by the Assert would almost surely complain, so that this warning will be seen in any non-assert build.) Some of these are of long standing while others are pretty recent, but it only seems worth fixing them in HEAD. Jaime Casanova, tweaked a bit by me Discussion: https://postgr.es/m/CAJGNTeMcYAMJdPAom52dppLMtF-UnEZi0dooj==75OEv1EoBZA@mail.gmail.com --- diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index de869e00ff..5bea073a2b 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -584,7 +584,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, if (include_image) { Page page = regbuf->page; - uint16 compressed_len; + uint16 compressed_len = 0; /* * The page needs to be backed up, so calculate its hole length diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index b4c2467710..80f561df1c 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -1593,6 +1593,8 @@ get_object_address_opf_member(ObjectType objtype, famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false); /* find out left/right type names and OIDs */ + typenames[0] = typenames[1] = NULL; + typeoids[0] = typeoids[1] = InvalidOid; i = 0; foreach(cell, lsecond(object)) { diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c index 66bfcced8d..d6794bf3de 100644 --- a/src/backend/utils/sort/logtape.c +++ b/src/backend/utils/sort/logtape.c @@ -411,7 +411,7 @@ ltsConcatWorkerTapes(LogicalTapeSet *lts, TapeShare *shared, SharedFileSet *fileset) { LogicalTape *lt = NULL; - long tapeblocks; + long tapeblocks = 0L; long nphysicalblocks = 0L; int i; diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 31ea6ca06e..d4209421f5 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -1495,6 +1495,7 @@ coerceToBool(PgBenchValue *pval, bool *bval) else /* NULL, INT or DOUBLE */ { fprintf(stderr, "cannot coerce %s to boolean\n", valueTypeName(pval)); + *bval = false; /* suppress uninitialized-variable warnings */ return false; } } @@ -1725,9 +1726,9 @@ evalLazyFunc(TState *thread, CState *st, * which do not require lazy evaluation. */ static bool -evalStandardFunc( - TState *thread, CState *st, - PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval) +evalStandardFunc(TState *thread, CState *st, + PgBenchFunction func, PgBenchExprLink *args, + PgBenchValue *retval) { /* evaluate all function arguments */ int nargs = 0;