]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Resolve Coverity DEADCODE
authorJohn Ferlan <jferlan@redhat.com>
Thu, 4 Sep 2014 19:08:49 +0000 (15:08 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 11 Sep 2014 12:06:16 +0000 (08:06 -0400)
Coverity points out that by using EMPTYSTR(type) we are guarding against
the possibility that it could be NULL; however, based on how 'type' was
initialized to NULL, then using nested ternary if-then-else's (?:?:)
setting either "ipv4", "ipv6", or "" - there is no way it could be NULL.
Since "-" is supposed to mean something empty in a field - modify the
nested ternary to an easier to read/process if-then-else leaving the
initialization to NULL to mean "-" in the formatted output.

Also changed the name from 'type' to 'typestr'.

Signed-off-by: John Ferlan <jferlan@redhat.com>
tools/virsh-network.c

index 5fe4b32661d9585c935a62d559f09734c6cd3161..90392d34797bbd0d788490da4a78ce80c2978b63 100644 (file)
@@ -1360,7 +1360,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
                   "---------------------------------------------------------");
 
     for (i = 0; i < nleases; i++) {
-        const char *type = NULL;
+        const char *typestr = NULL;
         char *cidr_format = NULL;
         virNetworkDHCPLeasePtr lease = leases[i];
         time_t expirytime_tmp = lease->expirytime;
@@ -1369,14 +1369,17 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
         ts = *localtime_r(&expirytime_tmp, &ts);
         strftime(expirytime, sizeof(expirytime), "%Y-%m-%d %H:%M:%S", &ts);
 
-        type = (lease->type == VIR_IP_ADDR_TYPE_IPV4) ? "ipv4" :
-            (lease->type == VIR_IP_ADDR_TYPE_IPV6) ? "ipv6" : "";
+        if (lease->type == VIR_IP_ADDR_TYPE_IPV4)
+            typestr = "ipv4";
+        else if (lease->type == VIR_IP_ADDR_TYPE_IPV6)
+            typestr = "ipv6";
 
         ignore_value(virAsprintf(&cidr_format, "%s/%d",
                                  lease->ipaddr, lease->prefix));
 
         vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n",
-                      expirytime, EMPTYSTR(lease->mac), EMPTYSTR(type), cidr_format,
+                      expirytime, EMPTYSTR(lease->mac),
+                      EMPTYSTR(typestr), cidr_format,
                       EMPTYSTR(lease->hostname), EMPTYSTR(lease->clientid));
     }