提交 7b48bb8c 编写于 作者: J Ján Tomko

Use g_strdup to fill in default values

Replace:
  if (!s && VIR_STRDUP(s, str) < 0)
    goto;
with:
  if (!s)
    s = g_strdup(str);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 3cbd4351
......@@ -13140,8 +13140,8 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt,
switch (def->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
path = virXPathString("string(./backend/device/@path)", ctxt);
if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0)
goto error;
if (!path)
path = g_strdup(VIR_DOMAIN_TPM_DEFAULT_DEVICE);
def->data.passthrough.source.data.file.path = g_steal_pointer(&path);
def->data.passthrough.source.type = VIR_DOMAIN_CHR_TYPE_DEV;
break;
......
......@@ -1414,8 +1414,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
return NULL;
if (!def->target.compat && VIR_STRDUP(def->target.compat, "1.1") < 0)
return NULL;
if (!def->target.compat)
def->target.compat = g_strdup("1.1");
if (!(def->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST)))
return NULL;
......
......@@ -156,9 +156,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
if (VIR_STRDUP((*parsedUri)->path, uri->path) < 0)
goto cleanup;
if (!(*parsedUri)->transport &&
VIR_STRDUP((*parsedUri)->transport, "https") < 0)
goto cleanup;
if (!(*parsedUri)->transport)
(*parsedUri)->transport = g_strdup("https");
result = 0;
......
......@@ -1034,8 +1034,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType)
(*anyType)->value =
(char *)xmlNodeListGetString(node->doc, node->children, 1);
if (!(*anyType)->value && VIR_STRDUP((*anyType)->value, "") < 0)
goto failure;
if (!(*anyType)->value)
(*anyType)->value = g_strdup("");
#define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \
do { \
......
......@@ -71,9 +71,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
}
}
if (!(*parsedUri)->transport &&
VIR_STRDUP((*parsedUri)->transport, "https") < 0)
goto cleanup;
if (!(*parsedUri)->transport)
(*parsedUri)->transport = g_strdup("https");
result = 0;
......
......@@ -1307,8 +1307,8 @@ udevSetParent(struct udev_device *device,
} while (def->parent == NULL && parent_device != NULL);
if (!def->parent && VIR_STRDUP(def->parent, "computer") < 0)
goto cleanup;
if (!def->parent)
def->parent = g_strdup("computer");
ret = 0;
......
......@@ -3735,9 +3735,8 @@ virQEMUCapsLoadCache(virArch hostArch,
if (virXPathBoolean("boolean(./package)", ctxt) > 0) {
qemuCaps->package = virXPathString("string(./package)", ctxt);
if (!qemuCaps->package &&
VIR_STRDUP(qemuCaps->package, "") < 0)
goto cleanup;
if (!qemuCaps->package)
qemuCaps->package = g_strdup("");
}
if (virXPathBoolean("boolean(./kernelVersion)", ctxt) > 0) {
......
......@@ -13339,9 +13339,8 @@ qemuDomainSetupDev(virQEMUDriverConfigPtr cfg,
mount_options = qemuSecurityGetMountOptions(mgr, vm->def);
if (!mount_options &&
VIR_STRDUP(mount_options, "") < 0)
goto cleanup;
if (!mount_options)
mount_options = g_strdup("");
/*
* tmpfs is limited to 64kb, since we only have device nodes in there
......
......@@ -3574,8 +3574,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
}
/* ifname: check if it's set in newdev. If not, retain the autogenerated one */
if (!newdev->ifname && VIR_STRDUP(newdev->ifname, olddev->ifname) < 0)
goto cleanup;
if (!newdev->ifname)
newdev->ifname = g_strdup(olddev->ifname);
if (STRNEQ_NULLABLE(olddev->ifname, newdev->ifname)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot modify network device tap name"));
......@@ -3603,9 +3603,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
goto cleanup;
}
/* grab alias from olddev if not set in newdev */
if (!newdev->info.alias &&
VIR_STRDUP(newdev->info.alias, olddev->info.alias) < 0)
goto cleanup;
if (!newdev->info.alias)
newdev->info.alias = g_strdup(olddev->info.alias);
/* device alias is checked already in virDomainDefCompatibleDevice */
......@@ -3617,9 +3616,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
goto cleanup;
}
if (!newdev->info.romfile &&
VIR_STRDUP(newdev->info.romfile, olddev->info.romfile) < 0)
goto cleanup;
if (!newdev->info.romfile)
newdev->info.romfile = g_strdup(olddev->info.romfile);
if (STRNEQ_NULLABLE(olddev->info.romfile, newdev->info.romfile)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot modify network rom file"));
......
......@@ -1247,8 +1247,8 @@ doRemoteOpen(virConnectPtr conn,
break;
case REMOTE_DRIVER_TRANSPORT_SSH:
if (!command && VIR_STRDUP(command, "ssh") < 0)
goto failed;
if (!command)
command = g_strdup("ssh");
if (!(priv->client = virNetClientNewSSH(priv->hostname,
port,
......
......@@ -459,8 +459,8 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr G_GNUC_UNUSED,
if (VIR_STRDUP(secdef->imagelabel, profile_name) < 0)
goto err;
if (!secdef->model && VIR_STRDUP(secdef->model, SECURITY_APPARMOR_NAME) < 0)
goto err;
if (!secdef->model)
secdef->model = g_strdup(SECURITY_APPARMOR_NAME);
/* Now that we have a label, load the profile into the kernel. */
if (load_profile(mgr, secdef->label, def, NULL, false) < 0) {
......
......@@ -938,9 +938,8 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr,
if (!seclabel->imagelabel)
goto cleanup;
if (!seclabel->model &&
VIR_STRDUP(seclabel->model, SECURITY_SELINUX_NAME) < 0)
goto cleanup;
if (!seclabel->model)
seclabel->model = g_strdup(SECURITY_SELINUX_NAME);
rc = 0;
......@@ -3368,8 +3367,8 @@ virSecuritySELinuxGetSecurityMountOptions(virSecurityManagerPtr mgr,
return NULL;
}
if (!opts && VIR_STRDUP(opts, "") < 0)
return NULL;
if (!opts)
opts = g_strdup("");
VIR_DEBUG("imageLabel=%s opts=%s",
secdef ? secdef->imagelabel : "(null)", opts);
......
......@@ -325,8 +325,8 @@ virStorageBackendLogicalMakeVol(char **const groups,
vol->target.backingStore->type = VIR_STORAGE_TYPE_BLOCK;
}
if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
goto cleanup;
if (!vol->key)
vol->key = g_strdup(groups[2]);
if (virStorageBackendUpdateVolInfo(vol, false,
VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < 0)
......
......@@ -136,8 +136,8 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
goto cleanup;
}
if (!volume->key && VIR_STRDUP(volume->key, tokens[0]) < 0)
goto cleanup;
if (!volume->key)
volume->key = g_strdup(tokens[0]);
if (volume->target.path == NULL) {
if (virAsprintf(&volume->target.path, "%s/%s",
......
......@@ -1100,8 +1100,8 @@ testOpenVolumesForPool(const char *file,
return -1;
}
if (!volDef->key && VIR_STRDUP(volDef->key, volDef->target.path) < 0)
return -1;
if (!volDef->key)
volDef->key = g_strdup(volDef->target.path);
if (virStoragePoolObjAddVol(obj, volDef) < 0)
return -1;
......
......@@ -4008,12 +4008,12 @@ virFileComparePaths(const char *p1, const char *p2)
* comparison.
*/
ignore_value(virFileResolveLink(p1, &res1));
if (!res1 && VIR_STRDUP(res1, p1) < 0)
return -1;
if (!res1)
res1 = g_strdup(p1);
ignore_value(virFileResolveLink(p2, &res2));
if (!res2 && VIR_STRDUP(res2, p2) < 0)
return -1;
if (!res2)
res2 = g_strdup(p2);
return STREQ_NULLABLE(res1, res2);
}
......
......@@ -106,12 +106,8 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new,
/* This is an ipv6 lease */
if ((server_duid_tmp
= virJSONValueObjectGetString(lease_tmp, "server-duid"))) {
if (!*server_duid && VIR_STRDUP(*server_duid, server_duid_tmp) < 0) {
/* Control reaches here when the 'action' is not for an
* ipv6 lease or, for some weird reason the env var
* DNSMASQ_SERVER_DUID wasn't set*/
return -1;
}
if (!*server_duid)
*server_duid = g_strdup(server_duid_tmp);
} else {
/* Inject server-duid into those ipv6 leases which
* didn't have it previously, for example, those
......
......@@ -2493,10 +2493,8 @@ virPCIGetNetName(const char *device_link_sysfs_path,
* needed because some NIC drivers (e.g. i40e)
* implement phys_port_id for PFs, but not for VFs
*/
if (!firstEntryName &&
VIR_STRDUP(firstEntryName, entry->d_name) < 0) {
goto cleanup;
}
if (!firstEntryName)
firstEntryName = g_strdup(entry->d_name);
continue;
}
......
......@@ -240,8 +240,8 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
param->value.s = va_arg(ap, char *);
}
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
return -1;
if (!param->value.s)
param->value.s = g_strdup("");
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
......
......@@ -2659,8 +2659,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
true) < 0)
goto cleanup;
if (!networkName && VIR_STRDUP(networkName, "") < 0)
goto cleanup;
if (!networkName)
networkName = g_strdup("");
}
/* vmx:vnet -> def:data.ifname */
......
......@@ -100,10 +100,8 @@ fillQemuCaps(virDomainCapsPtr domCaps,
goto cleanup;
}
if (!domCaps->machine &&
VIR_STRDUP(domCaps->machine,
virQEMUCapsGetPreferredMachine(qemuCaps)) < 0)
goto cleanup;
if (!domCaps->machine)
domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps));
if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册