Instead of repetitive:
s ? s : ""
use NULLSTR_EMPTY.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/datatypes.c | 2 +-
src/libvirt-admin.c | 2 +-
src/libvirt.c | 2 +-
src/lxc/lxc_controller.c | 2 +-
src/qemu/qemu_command.c | 8 +++-----
src/qemu/qemu_interface.c | 2 +-
src/qemu/qemu_migration_params.c | 2 +-
src/qemu/qemu_monitor_json.c | 2 +-
src/qemu/qemu_process.c | 4 ++--
src/util/vircgroupv1.c | 2 +-
src/util/vircgroupv2.c | 2 +-
src/util/virnetdevvportprofile.c | 4 ++--
src/util/virnuma.c | 4 ++--
src/util/virstoragefile.c | 2 +-
src/util/virsystemd.c | 4 ++--
src/util/viruri.c | 2 +-
src/xenconfig/xen_sxpr.c | 18 ++++++------------
tools/virsh-domain-monitor.c | 2 +-
tools/virsh-domain.c | 2 +-
tools/virt-admin.c | 4 ++--
20 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/src/datatypes.c b/src/datatypes.c
index be9b5286aa..9b92d892d5 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -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);
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index fb0190042a..74dedf64d8 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -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;
}
}
diff --git a/src/libvirt.c b/src/libvirt.c
index cc1c3c6ea1..854d70a2bf 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -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));
}
}
}
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 9c6ea97f1e..cd842f2980 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -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",
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 572d3bc20f..13f193a31d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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)
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index 2816db908a..c8effa68f4 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -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;
}
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 28f2c75ea1..24e5368783 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -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;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8bafa93c8d..cf474eb6c8 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7536c1cbb0..a62d89320b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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) {
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 14b3b6a45d..c172eb8b96 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -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;
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 655abfe42e..e0fa8e1cc0 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -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;
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 574887e9e0..fb05190c02 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -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)"));
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 67e6c86417..dd3fb7519e 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -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)) {
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 8319ba9c8c..90dbbfdd15 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -4181,7 +4181,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);
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index f492ac1859..b868f88a59 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -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",
diff --git a/src/util/viruri.c b/src/util/viruri.c
index c8811f64c6..8e45a447b9 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -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;
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 11af3e747a..eb535cde19 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -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:
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 49de81af8c..ad739a9df5 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -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);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0ea65e8994..07639ab8e3 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -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;
}
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index e613ad86f9..048c805f0a 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -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;
--
2.20.1