1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Use NULLSTR_EMPTY

Instead of repetitive:
  s ? s : ""
use NULLSTR_EMPTY.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Ján Tomko 2019-02-12 17:25:06 +01:00
parent 375f5317b7
commit 0f110d5ac8
22 changed files with 56 additions and 64 deletions

View File

@ -686,7 +686,7 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
ret->usageType = usageType;
if (VIR_STRDUP(ret->usageID, usageID ? usageID : "") < 0)
if (VIR_STRDUP(ret->usageID, NULLSTR_EMPTY(usageID)) < 0)
goto error;
ret->conn = virObjectRef(conn);

View File

@ -290,7 +290,7 @@ static struct netcf_if *interfaceDriverGetNetcfIF(struct netcf *ncf, virInterfac
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface named '%s': %s%s%s"),
ifinfo->name, errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
} else {
virReportError(VIR_ERR_NO_INTERFACE,
_("couldn't find interface named '%s'"),
@ -314,7 +314,7 @@ netcfInterfaceObjIsActive(struct netcf_if *iface,
virReportError(netcf_to_vir_err(errcode),
_("failed to get status of interface %s: %s%s%s"),
ncf_if_name(iface), errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -346,7 +346,7 @@ static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -364,7 +364,7 @@ static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to list host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -380,7 +380,7 @@ static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface named '%s': %s%s%s"),
names[i], errmsg,
details ? " - " : "", details ? details : "");
details ? " - " : "", NULLSTR_EMPTY(details));
goto cleanup;
} else {
/* Ignore the NETCF_NOERROR, as the interface is very likely
@ -436,7 +436,7 @@ static int netcfConnectListInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -454,7 +454,7 @@ static int netcfConnectListInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to list host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -475,7 +475,7 @@ static int netcfConnectListInterfacesImpl(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface named '%s': %s%s%s"),
allnames[i], errmsg,
details ? " - " : "", details ? details : "");
details ? " - " : "", NULLSTR_EMPTY(details));
goto cleanup;
} else {
/* Ignore the NETCF_NOERROR, as the interface is very likely
@ -622,7 +622,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -642,7 +642,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("failed to list host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -660,7 +660,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface named '%s': %s%s%s"),
names[i], errmsg,
details ? " - " : "", details ? details : "");
details ? " - " : "", NULLSTR_EMPTY(details));
goto cleanup;
} else {
/* Ignore the NETCF_NOERROR, as the interface is very likely
@ -740,7 +740,7 @@ static virInterfacePtr netcfInterfaceLookupByName(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface named '%s': %s%s%s"),
name, errmsg,
details ? " - " : "", details ? details : "");
details ? " - " : "", NULLSTR_EMPTY(details));
} else {
virReportError(VIR_ERR_NO_INTERFACE,
_("couldn't find interface named '%s'"), name);
@ -780,7 +780,7 @@ static virInterfacePtr netcfInterfaceLookupByMACString(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("couldn't find interface with MAC address '%s': %s%s%s"),
macstr, errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
if (niface == 0) {
@ -844,7 +844,7 @@ static char *netcfInterfaceGetXMLDesc(virInterfacePtr ifinfo,
virReportError(netcf_to_vir_err(errcode),
_("could not get interface XML description: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -906,7 +906,7 @@ static virInterfacePtr netcfInterfaceDefineXML(virConnectPtr conn,
virReportError(netcf_to_vir_err(errcode),
_("could not get interface XML description: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -948,7 +948,7 @@ static int netcfInterfaceUndefine(virInterfacePtr ifinfo)
virReportError(netcf_to_vir_err(errcode),
_("failed to undefine interface %s: %s%s%s"),
ifinfo->name, errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -1000,7 +1000,7 @@ static int netcfInterfaceCreate(virInterfacePtr ifinfo,
virReportError(netcf_to_vir_err(errcode),
_("failed to create (start) interface %s: %s%s%s"),
ifinfo->name, errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -1052,7 +1052,7 @@ static int netcfInterfaceDestroy(virInterfacePtr ifinfo,
virReportError(netcf_to_vir_err(errcode),
_("failed to destroy (stop) interface %s: %s%s%s"),
ifinfo->name, errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
goto cleanup;
}
@ -1115,7 +1115,7 @@ static int netcfInterfaceChangeBegin(virConnectPtr conn, unsigned int flags)
virReportError(netcf_to_vir_err(errcode),
_("failed to begin transaction: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
}
virObjectUnlock(driver);
@ -1140,7 +1140,7 @@ static int netcfInterfaceChangeCommit(virConnectPtr conn, unsigned int flags)
virReportError(netcf_to_vir_err(errcode),
_("failed to commit transaction: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
}
virObjectUnlock(driver);
@ -1165,7 +1165,7 @@ static int netcfInterfaceChangeRollback(virConnectPtr conn, unsigned int flags)
virReportError(netcf_to_vir_err(errcode),
_("failed to rollback transaction: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
NULLSTR_EMPTY(details));
}
virObjectUnlock(driver);

View File

@ -152,7 +152,7 @@ getSocketPath(virURIPtr uri)
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid URI path '%s', try '/system'"),
uri->path ? uri->path : "");
NULLSTR_EMPTY(uri->path));
goto error;
}
}

View File

@ -898,7 +898,7 @@ virConnectOpenInternal(const char *name,
goto failed;
VIR_DEBUG("%s driver URI probe returned '%s'",
virConnectDriverTab[i]->hypervisorDriver->name,
uristr ? uristr : "");
NULLSTR_EMPTY(uristr));
}
}
}

View File

@ -2160,7 +2160,7 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
/* XXX should we support gid=X for X!=5 for distros which use
* a different gid for tty? */
if (virAsprintf(&opts, "newinstance,ptmxmode=0666,mode=0620,gid=%u%s",
ptsgid, (mount_options ? mount_options : "")) < 0)
ptsgid, NULLSTR_EMPTY(mount_options)) < 0)
goto cleanup;
VIR_DEBUG("Mount devpts on %s type=tmpfs flags=0x%x, opts=%s",

View File

@ -579,7 +579,7 @@ virNWFilterSnoopReqNew(const char *ifkey)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopReqNew called with invalid "
"key \"%s\" (%zu)"),
ifkey ? ifkey : "",
NULLSTR_EMPTY(ifkey),
ifkey ? strlen(ifkey) : 0);
return NULL;
}

View File

@ -3726,9 +3726,9 @@ qemuBuildLegacyNicStr(virDomainNetDefPtr net)
virMacAddrFormat(&net->mac, macaddr),
net->info.alias,
(net->model ? ",model=" : ""),
(net->model ? net->model : ""),
NULLSTR_EMPTY(net->model),
(net->info.alias ? ",id=" : ""),
(net->info.alias ? net->info.alias : "")));
NULLSTR_EMPTY(net->info.alias)));
return str;
}
@ -3964,8 +3964,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
case VIR_DOMAIN_NET_TYPE_SERVER:
virBufferAsprintf(&buf, "socket,listen=%s:%d,",
net->data.socket.address ? net->data.socket.address
: "",
NULLSTR_EMPTY(net->data.socket.address),
net->data.socket.port);
break;
@ -7231,7 +7230,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
if (cpu) {
virCommandAddArg(cmd, "-cpu");
virCommandAddArgFormat(cmd, "%s%s", cpu, cpu_flags ? cpu_flags : "");
virCommandAddArgFormat(cmd, "%s%s", cpu, NULLSTR_EMPTY(cpu_flags));
}
ret = 0;
@ -10729,8 +10728,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
virCommandAddArg(cmd, qemucmd->args[i]);
for (i = 0; i < qemucmd->num_env; i++)
virCommandAddEnvPair(cmd, qemucmd->env_name[i],
qemucmd->env_value[i]
? qemucmd->env_value[i] : "");
NULLSTR_EMPTY(qemucmd->env_value[i]));
}
if (qemuBuildSeccompSandboxCommandLine(cmd, cfg, qemuCaps) < 0)

View File

@ -371,7 +371,7 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s: failed to communicate with bridge helper: %s%s"),
cmdstr, virStrerror(errno, ebuf, sizeof(ebuf)),
errstr ? errstr : "");
NULLSTR_EMPTY(errstr));
VIR_FREE(errstr);
goto cleanup;
}

View File

@ -930,7 +930,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
*tlsAlias) < 0 ||
qemuMigrationParamsSetString(migParams,
QEMU_MIGRATION_PARAM_TLS_HOSTNAME,
hostname ? hostname : "") < 0)
NULLSTR_EMPTY(hostname)) < 0)
goto error;
ret = 0;

View File

@ -1422,7 +1422,7 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
const char *data;
data = virJSONValueGetString(obj);
if (VIR_STRDUP(*reply_str, data ? data : "") < 0)
if (VIR_STRDUP(*reply_str, NULLSTR_EMPTY(data)) < 0)
goto cleanup;
}

View File

@ -4421,9 +4421,9 @@ qemuLogOperation(virDomainObjPtr vm,
(qemuVersion / 1000000) % 1000,
(qemuVersion / 1000) % 1000,
qemuVersion % 1000,
package ? package : "",
NULLSTR_EMPTY(package),
uts.release,
hostname ? hostname : "") < 0)
NULLSTR_EMPTY(hostname)) < 0)
goto cleanup;
if (cmd) {

View File

@ -532,7 +532,7 @@ virCgroupV1PathOfController(virCgroupPtr group,
if (virAsprintf(path, "%s%s/%s",
group->legacy[controller].mountPoint,
group->legacy[controller].placement,
key ? key : "") < 0)
NULLSTR_EMPTY(key)) < 0)
return -1;
return 0;

View File

@ -338,7 +338,7 @@ virCgroupV2PathOfController(virCgroupPtr group,
if (virAsprintf(path, "%s%s/%s",
group->unified.mountPoint,
group->unified.placement,
key ? key : "") < 0)
NULLSTR_EMPTY(key)) < 0)
return -1;
return 0;

View File

@ -1239,7 +1239,7 @@ virNetDevVPortProfileAssociate(const char *macvtap_ifname,
VIR_DEBUG("profile:'%p' vmOp: %s device: %s@%s mac: %s uuid: %s",
virtPort, virNetDevVPortProfileOpTypeToString(vmOp),
(macvtap_ifname ? macvtap_ifname : ""), linkdev,
NULLSTR_EMPTY(macvtap_ifname), linkdev,
(macvtap_macaddr
? virMacAddrFormat(macvtap_macaddr, macStr)
: "(unspecified)"),
@ -1305,7 +1305,7 @@ virNetDevVPortProfileDisassociate(const char *macvtap_ifname,
VIR_DEBUG("profile:'%p' vmOp: %s device: %s@%s mac: %s",
virtPort, virNetDevVPortProfileOpTypeToString(vmOp),
(macvtap_ifname ? macvtap_ifname : ""), linkdev,
NULLSTR_EMPTY(macvtap_ifname), linkdev,
(macvtap_macaddr
? virMacAddrFormat(macvtap_macaddr, macStr)
: "(unspecified)"));

View File

@ -487,13 +487,13 @@ virNumaGetHugePageInfoPath(char **path,
/* We are aiming at overall system info */
ret = virAsprintf(path,
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
page_size, suffix ? suffix : "");
page_size, NULLSTR_EMPTY(suffix));
} else {
/* We are aiming on specific NUMA node */
ret = virAsprintf(path,
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
HUGEPAGES_PREFIX "%ukB/%s",
node, page_size, suffix ? suffix : "");
node, page_size, NULLSTR_EMPTY(suffix));
}
if (ret >= 0 && !virFileExists(*path)) {

View File

@ -4119,7 +4119,7 @@ virStorageFileRemoveLastPathComponent(const char *path)
{
char *ret;
if (VIR_STRDUP(ret, path ? path : "") < 0)
if (VIR_STRDUP(ret, NULLSTR_EMPTY(path)) < 0)
return NULL;
virFileRemoveLastComponent(ret);

View File

@ -339,7 +339,7 @@ int virSystemdCreateMachine(const char *name,
creatorname,
iscontainer ? "container" : "vm",
(unsigned int)pidleader,
rootdir ? rootdir : "",
NULLSTR_EMPTY(rootdir),
nnicindexes, nicindexes,
3,
"Slice", "s", slicename,
@ -381,7 +381,7 @@ int virSystemdCreateMachine(const char *name,
creatorname,
iscontainer ? "container" : "vm",
(unsigned int)pidleader,
rootdir ? rootdir : "",
NULLSTR_EMPTY(rootdir),
3,
"Slice", "s", slicename,
"After", "as", 1, "libvirtd.service",

View File

@ -117,7 +117,7 @@ virURIParseParams(virURIPtr uri)
}
/* Append to the parameter set. */
if (virURIParamAppend(uri, name, value ? value : "") < 0) {
if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0) {
VIR_FREE(name);
VIR_FREE(value);
return -1;

View File

@ -1652,24 +1652,18 @@ xenFormatSxprChr(virDomainChrDefPtr def,
(def->source->data.tcp.protocol
== VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
"tcp" : "telnet"),
(def->source->data.tcp.host ?
def->source->data.tcp.host : ""),
(def->source->data.tcp.service ?
def->source->data.tcp.service : ""),
NULLSTR_EMPTY(def->source->data.tcp.host),
NULLSTR_EMPTY(def->source->data.tcp.service),
(def->source->data.tcp.listen ?
",server,nowait" : ""));
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
virBufferAsprintf(buf, "%s:%s:%s@%s:%s", type,
(def->source->data.udp.connectHost ?
def->source->data.udp.connectHost : ""),
(def->source->data.udp.connectService ?
def->source->data.udp.connectService : ""),
(def->source->data.udp.bindHost ?
def->source->data.udp.bindHost : ""),
(def->source->data.udp.bindService ?
def->source->data.udp.bindService : ""));
NULLSTR_EMPTY(def->source->data.udp.connectHost),
NULLSTR_EMPTY(def->source->data.udp.connectService),
NULLSTR_EMPTY(def->source->data.udp.bindHost),
NULLSTR_EMPTY(def->source->data.udp.bindService));
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:

View File

@ -2389,7 +2389,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
if (full || !j)
vshPrint(ctl, " %-10s %-17s %s\n",
iface->name,
iface->hwaddr ? iface->hwaddr : "", ip_addr_str);
NULLSTR_EMPTY(iface->hwaddr), ip_addr_str);
else
vshPrint(ctl, " %-10s %-17s %s\n",
"-", "-", ip_addr_str);

View File

@ -5524,7 +5524,7 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
if (virAsprintf(&ret, "%s-%s%s", virDomainGetName(dom),
timestr, ext ? ext : "") < 0) {
timestr, NULLSTR_EMPTY(ext)) < 0) {
vshError(ctl, "%s", _("Out of memory"));
return NULL;
}

View File

@ -1047,7 +1047,7 @@ cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd)
}
vshPrintExtra(ctl, " %-15s", _("Logging filters: "));
vshPrint(ctl, "%s\n", filters ? filters : "");
vshPrint(ctl, "%s\n", NULLSTR_EMPTY(filters));
}
return true;
@ -1101,7 +1101,7 @@ cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd)
}
vshPrintExtra(ctl, " %-15s", _("Logging outputs: "));
vshPrint(ctl, "%s\n", outputs ? outputs : "");
vshPrint(ctl, "%s\n", NULLSTR_EMPTY(outputs));
}
return true;