libadmin: Fix isAlias may be uninitialized warning 72/14772/6
authorMichael Meffie <mmeffie@sinenomine.net>
Mon, 23 Aug 2021 19:42:52 +0000 (15:42 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Sat, 4 Sep 2021 18:33:51 +0000 (14:33 -0400)
The cfgutil_HostNameIsAlias() function has an output parameter called
isAlias, which is used when cfgutil_HostIsAlias() returns non-zero.
However, it possible for isAlias to not be set before returning. GCC 12
issues a warning about the possible use of the uninitialized isAlias
variable:

    cfginternal.c:366:32: error: ‘isAlias’ may be used uninitialized
       [-Werror=maybe-uninitialized]

Initialize the cfgutil_HostNameIsAlias() isAlias output flag to false.
Also, fix the misleading code indentation around the
cfgutil_HostNameIsAlias() call.

Change-Id: I68e66ae5f9019a613187321bb792d0505959ed30
Reviewed-on: https://gerrit.openafs.org/14772
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/libadmin/cfg/cfginternal.c

index 1f581b8..f1abacb 100644 (file)
@@ -348,7 +348,7 @@ cfgutil_HostNameGetCellServDbAlias(const char *fsDbHost, const char *hostName,
                short dbhostFound = 0;
 
                while (!dbhostDone) {
-                   short isAlias;
+                   short isAlias = 0;
 
                    if (!bos_HostGetNext(dbIter, hostNameAlias, &tst2)) {
                        /* no more entries (or failure) */
@@ -357,15 +357,15 @@ cfgutil_HostNameGetCellServDbAlias(const char *fsDbHost, const char *hostName,
                        }
                        dbhostDone = 1;
 
-                   } else
-                       if (!cfgutil_HostNameIsAlias
-                           (hostName, hostNameAlias, &isAlias, &tst2)) {
-                       tst = tst2;
-                       dbhostDone = 1;
-
-                   } else if (isAlias) {
-                       dbhostFound = 1;
-                       dbhostDone = 1;
+                   } else {
+                       if (!cfgutil_HostNameIsAlias(hostName, hostNameAlias,
+                                                    &isAlias, &tst2)) {
+                           tst = tst2;
+                           dbhostDone = 1;
+                       } else if (isAlias) {
+                           dbhostFound = 1;
+                           dbhostDone = 1;
+                       }
                    }
                }