There's no need to guard virBufferEscapeString() with a call to
NULL as the very first thing the function does is check all three
arguments for NULL.
This patch was generated using the following spatch:
@@
expression X, Y, E;
@@
- if (E)
virBufferEscapeString(X, Y, E);
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/capabilities.c | 6 ++--
src/conf/domain_conf.c | 57 +++++++++++-------------------
src/conf/network_conf.c | 6 ++--
src/conf/node_device_conf.c | 57 ++++++++++++------------------
src/conf/snapshot_conf.c | 5 ++-
src/conf/storage_encryption_conf.c | 9 ++---
src/conf/storage_source_conf.c | 3 +-
src/conf/virnwfilterbindingdef.c | 3 +-
8 files changed, 55 insertions(+), 91 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index fe5e42c167..74e6293766 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -693,10 +693,8 @@ virCapabilitiesDomainDataLookupInternal(virCaps *caps,
if (domaintype > VIR_DOMAIN_VIRT_NONE)
virBufferAsprintf(&buf, "domaintype=%s ",
virDomainVirtTypeToString(domaintype));
- if (emulator)
- virBufferEscapeString(&buf, "emulator=%s ", emulator);
- if (machinetype)
- virBufferEscapeString(&buf, "machine=%s ", machinetype);
+ virBufferEscapeString(&buf, "emulator=%s ", emulator);
+ virBufferEscapeString(&buf, "machine=%s ", machinetype);
if (virBufferCurrentContent(&buf) &&
!virBufferCurrentContent(&buf)[0])
virBufferAsprintf(&buf, "%s", _("any
configuration"));
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fde594f811..2f1e99865b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5394,8 +5394,7 @@ virDomainDeviceInfoFormat(virBuffer *buf,
if (rombar)
virBufferAsprintf(buf, " bar='%s'", rombar);
}
- if (info->romfile)
- virBufferEscapeString(buf, " file='%s'",
info->romfile);
+ virBufferEscapeString(buf, " file='%s'", info->romfile);
virBufferAddLit(buf, "/>\n");
}
@@ -22175,8 +22174,7 @@ virSecurityDeviceLabelDefFormat(virBuffer *buf,
virBufferAddLit(buf, "<seclabel");
- if (def->model)
- virBufferEscapeString(buf, " model='%s'", def->model);
+ virBufferEscapeString(buf, " model='%s'", def->model);
if (def->labelskip)
virBufferAddLit(buf, " labelskip='yes'");
@@ -22371,8 +22369,7 @@ virDomainDiskSourceFormatNetwork(virBuffer *attrBuf,
virBufferAsprintf(childBuf, "<timeout
seconds='%llu'/>\n", src->timeout);
if (src->protocol == VIR_STORAGE_NET_PROTOCOL_SSH) {
- if (src->ssh_known_hosts_file)
- virBufferEscapeString(childBuf, "<knownHosts
path='%s'/>\n", src->ssh_known_hosts_file);
+ virBufferEscapeString(childBuf, "<knownHosts
path='%s'/>\n", src->ssh_known_hosts_file);
if (src->ssh_keyfile || src->ssh_agent) {
virBufferAddLit(childBuf, "<identity");
@@ -23162,8 +23159,7 @@ virDomainControllerDefFormat(virBuffer *buf,
" type='%s' index='%d'",
type, def->idx);
- if (model)
- virBufferEscapeString(&attrBuf, " model='%s'", model);
+ virBufferEscapeString(&attrBuf, " model='%s'", model);
switch (def->type) {
case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
@@ -24581,8 +24577,7 @@ virDomainChrTargetDefFormat(virBuffer *buf,
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN:
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
- if (def->target.name)
- virBufferEscapeString(buf, " name='%s'",
def->target.name);
+ virBufferEscapeString(buf, " name='%s'",
def->target.name);
if (def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO
&&
def->state != VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT &&
@@ -26004,9 +25999,8 @@ virDomainGraphicsDefFormat(virBuffer *buf,
break;
}
- if (def->data.vnc.keymap)
- virBufferEscapeString(buf, " keymap='%s'",
- def->data.vnc.keymap);
+ virBufferEscapeString(buf, " keymap='%s'",
+ def->data.vnc.keymap);
if (def->data.vnc.sharePolicy)
virBufferAsprintf(buf, " sharePolicy='%s'",
@@ -26021,13 +26015,11 @@ virDomainGraphicsDefFormat(virBuffer *buf,
break;
case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
- if (def->data.sdl.display)
- virBufferEscapeString(buf, " display='%s'",
- def->data.sdl.display);
+ virBufferEscapeString(buf, " display='%s'",
+ def->data.sdl.display);
- if (def->data.sdl.xauth)
- virBufferEscapeString(buf, " xauth='%s'",
- def->data.sdl.xauth);
+ virBufferEscapeString(buf, " xauth='%s'",
+ def->data.sdl.xauth);
if (def->data.sdl.fullscreen)
virBufferAddLit(buf, " fullscreen='yes'");
@@ -26066,9 +26058,8 @@ virDomainGraphicsDefFormat(virBuffer *buf,
break;
case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
- if (def->data.desktop.display)
- virBufferEscapeString(buf, " display='%s'",
- def->data.desktop.display);
+ virBufferEscapeString(buf, " display='%s'",
+ def->data.desktop.display);
if (def->data.desktop.fullscreen)
virBufferAddLit(buf, " fullscreen='yes'");
@@ -26121,9 +26112,8 @@ virDomainGraphicsDefFormat(virBuffer *buf,
break;
}
- if (def->data.spice.keymap)
- virBufferEscapeString(buf, " keymap='%s'",
- def->data.spice.keymap);
+ virBufferEscapeString(buf, " keymap='%s'",
+ def->data.spice.keymap);
if (def->data.spice.defaultMode !=
VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY)
virBufferAsprintf(buf, " defaultMode='%s'",
@@ -26503,11 +26493,9 @@ virDomainResourceDefFormat(virBuffer *buf,
if (!def)
return;
- if (def->partition)
- virBufferEscapeString(&childBuf,
"<partition>%s</partition>\n", def->partition);
+ virBufferEscapeString(&childBuf,
"<partition>%s</partition>\n", def->partition);
- if (def->appid)
- virBufferEscapeString(&childBuf, "<fibrechannel
appid='%s'/>\n", def->appid);
+ virBufferEscapeString(&childBuf, "<fibrechannel
appid='%s'/>\n", def->appid);
virXMLFormatElement(buf, "resource", NULL, &childBuf);
}
@@ -26680,11 +26668,9 @@ virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec)
virBufferAsprintf(&childBuf,
"<reducedPhysBits>%d</reducedPhysBits>\n",
sev->reduced_phys_bits);
virBufferAsprintf(&childBuf,
"<policy>0x%04x</policy>\n", sev->policy);
- if (sev->dh_cert)
- virBufferEscapeString(&childBuf,
"<dhCert>%s</dhCert>\n", sev->dh_cert);
+ virBufferEscapeString(&childBuf,
"<dhCert>%s</dhCert>\n", sev->dh_cert);
- if (sev->session)
- virBufferEscapeString(&childBuf,
"<session>%s</session>\n", sev->session);
+ virBufferEscapeString(&childBuf,
"<session>%s</session>\n", sev->session);
break;
}
@@ -27910,9 +27896,8 @@ virDomainDefFormatInternalSetRootName(virDomainDef *def,
for (i = 0; def->os.initenv && def->os.initenv[i]; i++)
virBufferAsprintf(buf, "<initenv
name='%s'>%s</initenv>\n",
def->os.initenv[i]->name,
def->os.initenv[i]->value);
- if (def->os.initdir)
- virBufferEscapeString(buf, "<initdir>%s</initdir>\n",
- def->os.initdir);
+ virBufferEscapeString(buf, "<initdir>%s</initdir>\n",
+ def->os.initdir);
if (def->os.inituser)
virBufferAsprintf(buf, "<inituser>%s</inituser>\n",
def->os.inituser);
if (def->os.initgroup)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index cc92ed0b03..f5ccf4bd12 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -2004,10 +2004,8 @@ virNetworkDNSDefFormat(virBuffer *buf,
def->srvs[i].service);
virBufferEscapeString(buf, "protocol='%s'",
def->srvs[i].protocol);
- if (def->srvs[i].domain)
- virBufferEscapeString(buf, " domain='%s'",
def->srvs[i].domain);
- if (def->srvs[i].target)
- virBufferEscapeString(buf, " target='%s'",
def->srvs[i].target);
+ virBufferEscapeString(buf, " domain='%s'",
def->srvs[i].domain);
+ virBufferEscapeString(buf, " target='%s'",
def->srvs[i].target);
if (def->srvs[i].port)
virBufferAsprintf(buf, " port='%d'",
def->srvs[i].port);
if (def->srvs[i].priority)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index fe6d9a36b2..d2b578178b 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -176,20 +176,16 @@ virNodeDeviceCapSystemDefFormat(virBuffer *buf,
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (data->system.product_name)
- virBufferEscapeString(buf, "<product>%s</product>\n",
- data->system.product_name);
+ virBufferEscapeString(buf, "<product>%s</product>\n",
+ data->system.product_name);
virBufferAddLit(buf, "<hardware>\n");
virBufferAdjustIndent(buf, 2);
- if (data->system.hardware.vendor_name)
- virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
- data->system.hardware.vendor_name);
- if (data->system.hardware.version)
- virBufferEscapeString(buf, "<version>%s</version>\n",
- data->system.hardware.version);
- if (data->system.hardware.serial)
- virBufferEscapeString(buf, "<serial>%s</serial>\n",
- data->system.hardware.serial);
+ virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
+ data->system.hardware.vendor_name);
+ virBufferEscapeString(buf, "<version>%s</version>\n",
+ data->system.hardware.version);
+ virBufferEscapeString(buf, "<serial>%s</serial>\n",
+ data->system.hardware.serial);
virUUIDFormat(data->system.hardware.uuid, uuidstr);
virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr);
virBufferAdjustIndent(buf, -2);
@@ -197,15 +193,12 @@ virNodeDeviceCapSystemDefFormat(virBuffer *buf,
virBufferAddLit(buf, "<firmware>\n");
virBufferAdjustIndent(buf, 2);
- if (data->system.firmware.vendor_name)
- virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
- data->system.firmware.vendor_name);
- if (data->system.firmware.version)
- virBufferEscapeString(buf, "<version>%s</version>\n",
- data->system.firmware.version);
- if (data->system.firmware.release_date)
- virBufferEscapeString(buf,
"<release_date>%s</release_date>\n",
- data->system.firmware.release_date);
+ virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
+ data->system.firmware.vendor_name);
+ virBufferEscapeString(buf, "<version>%s</version>\n",
+ data->system.firmware.version);
+ virBufferEscapeString(buf,
"<release_date>%s</release_date>\n",
+ data->system.firmware.release_date);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</firmware>\n");
}
@@ -225,9 +218,8 @@ virNodeDeviceCapMdevTypesFormat(virBuffer *buf,
virMediatedDeviceType *type = mdev_types[i];
virBufferEscapeString(buf, "<type id='%s'>\n",
type->id);
virBufferAdjustIndent(buf, 2);
- if (type->name)
- virBufferEscapeString(buf, "<name>%s</name>\n",
- type->name);
+ virBufferEscapeString(buf, "<name>%s</name>\n",
+ type->name);
virBufferEscapeString(buf,
"<deviceAPI>%s</deviceAPI>\n",
type->device_api);
virBufferAsprintf(buf,
@@ -454,10 +446,9 @@ virNodeDeviceCapUSBInterfaceDefFormat(virBuffer *buf,
data->usb_if.subclass);
virBufferAsprintf(buf, "<protocol>%d</protocol>\n",
data->usb_if.protocol);
- if (data->usb_if.description)
- virBufferEscapeString(buf,
- "<description>%s</description>\n",
- data->usb_if.description);
+ virBufferEscapeString(buf,
+ "<description>%s</description>\n",
+ data->usb_if.description);
}
@@ -469,9 +460,8 @@ virNodeDeviceCapNetDefFormat(virBuffer *buf,
virBufferEscapeString(buf, "<interface>%s</interface>\n",
data->net.ifname);
- if (data->net.address)
- virBufferEscapeString(buf, "<address>%s</address>\n",
- data->net.address);
+ virBufferEscapeString(buf, "<address>%s</address>\n",
+ data->net.address);
virInterfaceLinkFormat(buf, &data->net.lnk);
if (data->net.features) {
for (i = 0; i < VIR_NET_DEV_FEAT_LAST; i++) {
@@ -533,9 +523,8 @@ virNodeDeviceCapSCSIDefFormat(virBuffer *buf,
virBufferAsprintf(buf, "<target>%d</target>\n",
data->scsi.target);
virBufferAsprintf(buf, "<lun>%d</lun>\n", data->scsi.lun);
- if (data->scsi.type)
- virBufferEscapeString(buf, "<type>%s</type>\n",
- data->scsi.type);
+ virBufferEscapeString(buf, "<type>%s</type>\n",
+ data->scsi.type);
}
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index d7fcded302..039ed77b84 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -819,9 +819,8 @@ virDomainSnapshotDefFormatInternal(virBuffer *buf,
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<name>%s</name>\n",
def->parent.name);
- if (def->parent.description)
- virBufferEscapeString(buf,
"<description>%s</description>\n",
- def->parent.description);
+ virBufferEscapeString(buf, "<description>%s</description>\n",
+ def->parent.description);
if (def->state)
virBufferAsprintf(buf, "<state>%s</state>\n",
virDomainSnapshotStateTypeToString(def->state));
diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c
index 1849df5c6c..b86001ec50 100644
--- a/src/conf/storage_encryption_conf.c
+++ b/src/conf/storage_encryption_conf.c
@@ -317,16 +317,13 @@ virStorageEncryptionInfoDefFormat(virBuffer *buf,
{
virBufferEscapeString(buf, "<cipher name='%s'",
enc->cipher_name);
virBufferAsprintf(buf, " size='%u'", enc->cipher_size);
- if (enc->cipher_mode)
- virBufferEscapeString(buf, " mode='%s'", enc->cipher_mode);
- if (enc->cipher_hash)
- virBufferEscapeString(buf, " hash='%s'", enc->cipher_hash);
+ virBufferEscapeString(buf, " mode='%s'", enc->cipher_mode);
+ virBufferEscapeString(buf, " hash='%s'", enc->cipher_hash);
virBufferAddLit(buf, "/>\n");
if (enc->ivgen_name) {
virBufferEscapeString(buf, "<ivgen name='%s'",
enc->ivgen_name);
- if (enc->ivgen_hash)
- virBufferEscapeString(buf, " hash='%s'",
enc->ivgen_hash);
+ virBufferEscapeString(buf, " hash='%s'", enc->ivgen_hash);
virBufferAddLit(buf, "/>\n");
}
}
diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c
index 959ec5ed40..908bc5fab2 100644
--- a/src/conf/storage_source_conf.c
+++ b/src/conf/storage_source_conf.c
@@ -1347,8 +1347,7 @@ int
virStorageSourcePrivateDataFormatRelPath(virStorageSource *src,
virBuffer *buf)
{
- if (src->relPath)
- virBufferEscapeString(buf, "<relPath>%s</relPath>\n",
src->relPath);
+ virBufferEscapeString(buf, "<relPath>%s</relPath>\n",
src->relPath);
return 0;
}
diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c
index 423ed7a392..fe45c84347 100644
--- a/src/conf/virnwfilterbindingdef.c
+++ b/src/conf/virnwfilterbindingdef.c
@@ -203,8 +203,7 @@ virNWFilterBindingDefFormatBuf(virBuffer *buf,
virBufferAddLit(buf, "</owner>\n");
virBufferEscapeString(buf, "<portdev name='%s'/>\n",
def->portdevname);
- if (def->linkdevname)
- virBufferEscapeString(buf, "<linkdev name='%s'/>\n",
def->linkdevname);
+ virBufferEscapeString(buf, "<linkdev name='%s'/>\n",
def->linkdevname);
virMacAddrFormat(&def->mac, mac);
virBufferAsprintf(buf, "<mac address='%s'/>\n", mac);
--
2.44.2