back-port one-line gcc-10+ warning fix to REL_10_STABLE - Mailing list pgsql-hackers

From Anton Voloshin
Subject back-port one-line gcc-10+ warning fix to REL_10_STABLE
Date
Msg-id be8bbcdf-35f8-a8a6-098f-65c2e9497151@postgrespro.ru
Whole thread Raw
Responses Re: back-port one-line gcc-10+ warning fix to REL_10_STABLE
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Tatsuro Yamada
Date:
Subject: Re: Duplicate history file?
Next
From: Kyotaro Horiguchi
Date:
Subject: Re: Logical replication keepalive flood