mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
lib: Use NULLSTR family of macros more
There is a family of convenient macros: NULLSTR, NULLSTR_EMPTY, NULLSTR_STAR, NULLSTR_MINUS which hides ternary operator. Generated using the following spatch (and its obvious variants): @@ expression s; @@ <+... - s ? s : "<null>" + NULLSTR(s) ...+> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
3780522968
commit
ab7f877f27
@ -168,7 +168,7 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
|
||||
}
|
||||
|
||||
if (cred[i].type != VIR_CRED_EXTERNAL) {
|
||||
cred[i].result = bufptr ? bufptr : g_strdup(cred[i].defresult ? cred[i].defresult : "");
|
||||
cred[i].result = bufptr ? bufptr : g_strdup(NULLSTR_EMPTY(cred[i].defresult));
|
||||
cred[i].resultlen = strlen(cred[i].result);
|
||||
}
|
||||
}
|
||||
|
@ -867,10 +867,10 @@ iptablesForwardMasquerade(virFirewall *fw,
|
||||
if (addrStartStr && addrStartStr[0]) {
|
||||
if (addrEndStr && addrEndStr[0]) {
|
||||
natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
|
||||
portRangeStr ? portRangeStr : "");
|
||||
NULLSTR_EMPTY(portRangeStr));
|
||||
} else {
|
||||
natRangeStr = g_strdup_printf("%s%s", addrStartStr,
|
||||
portRangeStr ? portRangeStr : "");
|
||||
NULLSTR_EMPTY(portRangeStr));
|
||||
}
|
||||
|
||||
virFirewallCmdAddArgList(fw, fwCmd,
|
||||
|
@ -588,10 +588,10 @@ nftablesAddForwardMasquerade(virFirewall *fw,
|
||||
if (addrStartStr && addrStartStr[0]) {
|
||||
if (addrEndStr && addrEndStr[0]) {
|
||||
natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
|
||||
portRangeStr ? portRangeStr : "");
|
||||
NULLSTR_EMPTY(portRangeStr));
|
||||
} else {
|
||||
natRangeStr = g_strdup_printf("%s%s", addrStartStr,
|
||||
portRangeStr ? portRangeStr : "");
|
||||
NULLSTR_EMPTY(portRangeStr));
|
||||
}
|
||||
|
||||
virFirewallCmdAddArgList(fw, fwCmd, "counter", "snat", "to", natRangeStr, NULL);
|
||||
|
@ -1090,7 +1090,7 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def,
|
||||
|
||||
loader->nvram->path = g_strdup_printf("%s/%s_VARS%s",
|
||||
cfg->nvramDir, def->name,
|
||||
ext ? ext : "");
|
||||
NULLSTR_EMPTY(ext));
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,8 +188,8 @@ virNetDevIPAddrAdd(const char *ifname,
|
||||
|
||||
VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s",
|
||||
NULLSTR(ipStr), prefix,
|
||||
peerStr ? " peer " : "", peerStr ? peerStr : "",
|
||||
bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
|
||||
peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr),
|
||||
bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr),
|
||||
ifname);
|
||||
|
||||
if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
|
||||
@ -206,8 +206,8 @@ virNetDevIPAddrAdd(const char *ifname,
|
||||
virReportError(VIR_ERR_SYSTEM_ERROR,
|
||||
_("Failed to add IP address %1$s/%2$d%3$s%4$s%5$s%6$s to %7$s"),
|
||||
ipStr, prefix,
|
||||
peerStr ? " peer " : "", peerStr ? peerStr : "",
|
||||
bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
|
||||
peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr),
|
||||
bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr),
|
||||
ifname);
|
||||
return -1;
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ cmdCheckpointInfo(vshControl *ctl,
|
||||
_("unexpected problem querying checkpoint state"));
|
||||
return false;
|
||||
}
|
||||
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-");
|
||||
vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_MINUS(parent));
|
||||
|
||||
/* Children, Descendants. */
|
||||
flags = 0;
|
||||
|
@ -712,11 +712,11 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
|
||||
mac = virXPathString("string(./mac/@address)", ctxt);
|
||||
|
||||
if (vshTableRowAppend(table,
|
||||
target ? target : "-",
|
||||
NULLSTR_MINUS(target),
|
||||
type,
|
||||
source ? source : "-",
|
||||
model ? model : "-",
|
||||
mac ? mac : "-",
|
||||
NULLSTR_MINUS(source),
|
||||
NULLSTR_MINUS(model),
|
||||
NULLSTR_MINUS(mac),
|
||||
NULL) < 0)
|
||||
return false;
|
||||
}
|
||||
|
@ -1233,7 +1233,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
parent = virNodeDeviceGetParent(device);
|
||||
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
|
||||
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "");
|
||||
vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_EMPTY(parent));
|
||||
vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device) ?
|
||||
_("yes") : _("no"));
|
||||
vshPrint(ctl, "%-15s %s\n", _("Persistent:"),
|
||||
|
Loading…
Reference in New Issue
Block a user