[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 09/26] virsh: Resolve Coverity DEADCODE



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 either "ipv4", "ipv6", or "" - there is no way
it could be NULL.  Since "-" is supposed to mean something empty in a
field - remove the initialization to NULL and use it as the ending else
rather than using "".

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

Signed-off-by: John Ferlan <jferlan redhat com>
---
 tools/virsh-network.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 5fe4b32..f505c14 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -1360,7 +1360,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
                   "---------------------------------------------------------");
 
     for (i = 0; i < nleases; i++) {
-        const char *type = NULL;
+        const char *typestr;
         char *cidr_format = NULL;
         virNetworkDHCPLeasePtr lease = leases[i];
         time_t expirytime_tmp = lease->expirytime;
@@ -1369,14 +1369,15 @@ 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" : "";
+        typestr = (lease->type == VIR_IP_ADDR_TYPE_IPV4) ? "ipv4" :
+            (lease->type == VIR_IP_ADDR_TYPE_IPV6) ? "ipv6" : NULL;
 
         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));
     }
 
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]