back-port one-line gcc-10+ warning fix to REL_10_STABLE

Started by Anton Voloshinover 4 years ago2 messages
#1Anton Voloshin
a.voloshin@postgrespro.ru
1 attachment(s)

Hello, hackers,

Currently, REL_10_STABLE can't be compiled with gcc-10 or 11, -Werror
and "./configure" without arguments. E.g. gcc-11 gives an error:

objectaddress.c:1618:99: error: ‘typeoids’ may be used uninitialized
[-Werror=maybe-uninitialized]
1618 |
ObjectIdGetDatum(typeoids[1]),
...
objectaddress.c: In function ‘get_object_address’:
objectaddress.c:1578:33: note: ‘typeoids’ declared here
1578 | Oid typeoids[2];
| ^~~~~~~~

gcc-10 gives a similar error.

I propose to back-port a small part of Tom Lane's commit 9a725f7b5cb7,
which was somehow never back-ported to REL_10_STABLE. The fix is
explicit initialization to InvalidOid for the typeoids[2] variable involved.

Even if, technically, the initialization is probably not required (or
so I've heard), in PostgreSQL 11+ it was deemed that explicit
initialization is acceptable here to avoid compiler warning.

Please note that above-mentioned commit 9a725f7b5cb7 adds initialization
for a variable from the previous line, typenames[2] as well, but since
gcc 10 and 11 don't warn on that, I guess there is no need to add that
initialization as well.

The proposed one-line patch is attached, but basically it is:
diff --git a/src/backend/catalog/objectaddress.c 
b/src/backend/catalog/objectaddress.c
index b0ff255a593..8cc9dc003c8 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1591,6 +1591,7 @@ get_object_address_opf_member(ObjectType objtype,
  	famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);

/* find out left/right type names and OIDs */
+ typeoids[0] = typeoids[1] = InvalidOid;
i = 0;
foreach(cell, lsecond(object))
{

I've verified that all other current branches, i.e.
REL9_6_STABLE..REL_13_STABLE (excluding REL_10_STABLE) and master can
compile cleanly even with bare ./configure without arguments using gcc-11.

--
Anton Voloshin
Postgres Professional, The Russian Postgres Company
https://postgrespro.ru

Attachments:

v1-objectaddress-warning.patchtext/x-patch; charset=UTF-8; name=v1-objectaddress-warning.patchDownload
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index b0ff255a593..8cc9dc003c8 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1591,6 +1591,7 @@ get_object_address_opf_member(ObjectType objtype,
 	famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
 
 	/* find out left/right type names and OIDs */
+	typeoids[0] = typeoids[1] = InvalidOid;
 	i = 0;
 	foreach(cell, lsecond(object))
 	{
#2Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Anton Voloshin (#1)
Re: back-port one-line gcc-10+ warning fix to REL_10_STABLE

On 2021-Jun-07, Anton Voloshin wrote:

Hello, hackers,

Currently, REL_10_STABLE can't be compiled with gcc-10 or 11, -Werror and
"./configure" without arguments. E.g. gcc-11 gives an error:

Hi, thanks for the report. I noticed that the commit that introduced
this (41306a511c01) was introduced in 9.5, so I was surprised that you
report it doesn't complain in 9.6. Turns out that Peter E had fixed the
issue, but only in 9.5 and 9.6; I don't really understand why no fix was
applied to 10. I forward-ported that commit to 10, which should also
fix the problem. Branches 11 and up already have Tom Lane's fix.

--
�lvaro Herrera Valdivia, Chile
"[PostgreSQL] is a great group; in my opinion it is THE best open source
development communities in existence anywhere." (Lamar Owen)