From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Wed, 1 Jun 2022 21:21:45 +0000 (-0400)
Subject: Silence compiler warnings from some older compilers.
X-Git-Tag: REL_10_22~55
X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=c051180147760fbb56b38bad311b427e57ac8cab;p=postgresql.git

Silence compiler warnings from some older compilers.

Since a117cebd6, some older gcc versions issue "variable may be used
uninitialized in this function" complaints for brin_summarize_range.
Silence that using the same coding pattern as in bt_index_check_internal;
arguably, a117cebd6 had too narrow a view of which compilers might give
trouble.

Nathan Bossart and Tom Lane.  Back-patch as the previous commit was.

Discussion: https://postgr.es/m/20220601163537.GA2331988@nathanxps13
---

diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 29b4170a7eb..7211ce72d08 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -199,7 +199,7 @@ bt_index_check_internal(Oid indrelid, bool parentcheck)
 	else
 	{
 		heaprel = NULL;
-		/* for "gcc -Og" https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78394 */
+		/* Set these just to suppress "uninitialized variable" warnings */
 		save_userid = InvalidOid;
 		save_sec_context = -1;
 		save_nestlevel = -1;
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index fdedb6252bf..6e88871d9e8 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -913,7 +913,13 @@ brin_summarize_range(PG_FUNCTION_ARGS)
 		save_nestlevel = NewGUCNestLevel();
 	}
 	else
+	{
 		heapRel = NULL;
+		/* Set these just to suppress "uninitialized variable" warnings */
+		save_userid = InvalidOid;
+		save_sec_context = -1;
+		save_nestlevel = -1;
+	}
 
 	indexRel = index_open(indexoid, ShareUpdateExclusiveLock);