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:
Michal Privoznik 2024-08-19 12:26:27 +02:00
parent 3780522968
commit ab7f877f27
8 changed files with 16 additions and 16 deletions

View File

@ -168,7 +168,7 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
} }
if (cred[i].type != VIR_CRED_EXTERNAL) { 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); cred[i].resultlen = strlen(cred[i].result);
} }
} }

View File

@ -867,10 +867,10 @@ iptablesForwardMasquerade(virFirewall *fw,
if (addrStartStr && addrStartStr[0]) { if (addrStartStr && addrStartStr[0]) {
if (addrEndStr && addrEndStr[0]) { if (addrEndStr && addrEndStr[0]) {
natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr, natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
portRangeStr ? portRangeStr : ""); NULLSTR_EMPTY(portRangeStr));
} else { } else {
natRangeStr = g_strdup_printf("%s%s", addrStartStr, natRangeStr = g_strdup_printf("%s%s", addrStartStr,
portRangeStr ? portRangeStr : ""); NULLSTR_EMPTY(portRangeStr));
} }
virFirewallCmdAddArgList(fw, fwCmd, virFirewallCmdAddArgList(fw, fwCmd,

View File

@ -588,10 +588,10 @@ nftablesAddForwardMasquerade(virFirewall *fw,
if (addrStartStr && addrStartStr[0]) { if (addrStartStr && addrStartStr[0]) {
if (addrEndStr && addrEndStr[0]) { if (addrEndStr && addrEndStr[0]) {
natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr, natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
portRangeStr ? portRangeStr : ""); NULLSTR_EMPTY(portRangeStr));
} else { } else {
natRangeStr = g_strdup_printf("%s%s", addrStartStr, natRangeStr = g_strdup_printf("%s%s", addrStartStr,
portRangeStr ? portRangeStr : ""); NULLSTR_EMPTY(portRangeStr));
} }
virFirewallCmdAddArgList(fw, fwCmd, "counter", "snat", "to", natRangeStr, NULL); virFirewallCmdAddArgList(fw, fwCmd, "counter", "snat", "to", natRangeStr, NULL);

View File

@ -1090,7 +1090,7 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def,
loader->nvram->path = g_strdup_printf("%s/%s_VARS%s", loader->nvram->path = g_strdup_printf("%s/%s_VARS%s",
cfg->nvramDir, def->name, cfg->nvramDir, def->name,
ext ? ext : ""); NULLSTR_EMPTY(ext));
} }

View File

@ -188,8 +188,8 @@ virNetDevIPAddrAdd(const char *ifname,
VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s",
NULLSTR(ipStr), prefix, NULLSTR(ipStr), prefix,
peerStr ? " peer " : "", peerStr ? peerStr : "", peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr),
bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr),
ifname); ifname);
if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname, if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
@ -206,8 +206,8 @@ virNetDevIPAddrAdd(const char *ifname,
virReportError(VIR_ERR_SYSTEM_ERROR, 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"), _("Failed to add IP address %1$s/%2$d%3$s%4$s%5$s%6$s to %7$s"),
ipStr, prefix, ipStr, prefix,
peerStr ? " peer " : "", peerStr ? peerStr : "", peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr),
bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr),
ifname); ifname);
return -1; return -1;
} }

View File

@ -455,7 +455,7 @@ cmdCheckpointInfo(vshControl *ctl,
_("unexpected problem querying checkpoint state")); _("unexpected problem querying checkpoint state"));
return false; return false;
} }
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-"); vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_MINUS(parent));
/* Children, Descendants. */ /* Children, Descendants. */
flags = 0; flags = 0;

View File

@ -712,11 +712,11 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
mac = virXPathString("string(./mac/@address)", ctxt); mac = virXPathString("string(./mac/@address)", ctxt);
if (vshTableRowAppend(table, if (vshTableRowAppend(table,
target ? target : "-", NULLSTR_MINUS(target),
type, type,
source ? source : "-", NULLSTR_MINUS(source),
model ? model : "-", NULLSTR_MINUS(model),
mac ? mac : "-", NULLSTR_MINUS(mac),
NULL) < 0) NULL) < 0)
return false; return false;
} }

View File

@ -1233,7 +1233,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
parent = virNodeDeviceGetParent(device); parent = virNodeDeviceGetParent(device);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(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) ? vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device) ?
_("yes") : _("no")); _("yes") : _("no"));
vshPrint(ctl, "%-15s %s\n", _("Persistent:"), vshPrint(ctl, "%-15s %s\n", _("Persistent:"),