From b46b7785acc131b061b2b9c5f7fedb2ad1929ae5 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Thu, 4 Sep 2014 15:08:49 -0400 Subject: [PATCH] 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 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 --- tools/virsh-network.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 5fe4b32661..90392d3479 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 = 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)); } -- GitLab