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 <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2014-09-04 15:08:49 -04:00
parent 6825bdad13
commit b46b7785ac
1 changed files with 7 additions and 4 deletions

View 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));
}