From nobody Mon Feb 9 05:40:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571576191; cv=none; d=zoho.com; s=zohoarc; b=kv90SS+wodNJ2jqY/LP5hAXCAUN31rhFXNxLvvaXotoof3C1AU1yCQGQUKTRnKe3NSCDpPs7xD9HRnHKxMv+wn2C4IUWRWnPMYJRqVin/yNzT8Slbtoo1j39MNaFsT8/Qqdic/sbpRKTuClu0wyP5DR1f2CVD8aEeIcMKCaAs0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571576191; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gfKzAszrbPtiuXxBi0D+kurVMh/uxYKXlA+s2ajPuwU=; b=WyD0mDUgxMEI80iCay9O+dA2uyfTGQK1dvulmUlckHdTHayv/eypsz2dWUndcOP3UeTDhNgLSm1Q2GPtZKELxMu6E4qv+EvIYVLscW7qDJ6RpqHYUIzCs6xZjzev3lTnXQLwyUQkUq8sVuNlaF5hbRbHSS5sZFN4Gopm3Px9URY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571576190991524.2319080357219; Sun, 20 Oct 2019 05:56:30 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-kDbwipA8PMKa-nD-E7jnUw-1; Sun, 20 Oct 2019 08:56:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 493AF1800E0E; Sun, 20 Oct 2019 12:56:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 234BA6012D; Sun, 20 Oct 2019 12:56:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DA8EF180BAA3; Sun, 20 Oct 2019 12:56:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9KCten1023367 for ; Sun, 20 Oct 2019 08:55:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18A773CC8; Sun, 20 Oct 2019 12:55:40 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-23.brq.redhat.com [10.40.200.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6713B196AE for ; Sun, 20 Oct 2019 12:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571576189; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=gfKzAszrbPtiuXxBi0D+kurVMh/uxYKXlA+s2ajPuwU=; b=J641FN+WcYkgsgnj/UuUrdcKjqM1vHD3LYB3elf8ZnB6B/ilRZ7p96R0lskUzpE0vlfO96 boywoqGeXJpIT3rkBUUapg/o7NtHA7XtScy25tBYVecpk6yudsv33nqLfi/yV73IQWRTgi tQ1XX1P2zwLX/AinRwSKYuiM1dEN6Rw= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Sun, 20 Oct 2019 14:55:26 +0200 Message-Id: <6b53eacf8009a28673ec61ed991dd72cb949f38d.1571575889.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/34] Use g_strdup to fill in default values X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: kDbwipA8PMKa-nD-E7jnUw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace: if (!s && VIR_STRDUP(s, str) < 0) goto; with: if (!s) s =3D g_strdup(str); Signed-off-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 4 ++-- src/conf/storage_conf.c | 4 ++-- src/esx/esx_util.c | 5 ++--- src/esx/esx_vi_types.c | 4 ++-- src/hyperv/hyperv_util.c | 5 ++--- src/node_device/node_device_udev.c | 4 ++-- src/qemu/qemu_capabilities.c | 5 ++--- src/qemu/qemu_domain.c | 5 ++--- src/qemu/qemu_hotplug.c | 14 ++++++-------- src/remote/remote_driver.c | 4 ++-- src/security/security_apparmor.c | 4 ++-- src/security/security_selinux.c | 9 ++++----- src/storage/storage_backend_logical.c | 4 ++-- src/storage/storage_backend_zfs.c | 4 ++-- src/test/test_driver.c | 4 ++-- src/util/virfile.c | 8 ++++---- src/util/virlease.c | 8 ++------ src/util/virpci.c | 6 ++---- src/util/virtypedparam.c | 4 ++-- src/vmx/vmx.c | 4 ++-- tests/domaincapstest.c | 6 ++---- 21 files changed, 50 insertions(+), 65 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cd9b6ca993..d0dd7b3fa9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13140,8 +13140,8 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: path =3D virXPathString("string(./backend/device/@path)", ctxt); - if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0) - goto error; + if (!path) + path =3D g_strdup(VIR_DOMAIN_TPM_DEFAULT_DEVICE); def->data.passthrough.source.data.file.path =3D g_steal_pointer(&p= ath); def->data.passthrough.source.type =3D VIR_DOMAIN_CHR_TYPE_DEV; break; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 9e4978b560..ba3e3ec326 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1414,8 +1414,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if ((n =3D virXPathNodeSet("./target/features/*", ctxt, &nodes)) <= 0) return NULL; =20 - if (!def->target.compat && VIR_STRDUP(def->target.compat, "1.1") <= 0) - return NULL; + if (!def->target.compat) + def->target.compat =3D g_strdup("1.1"); =20 if (!(def->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATU= RE_LAST))) return NULL; diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index d7210375fa..1bed01054b 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -156,9 +156,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIP= tr uri) if (VIR_STRDUP((*parsedUri)->path, uri->path) < 0) goto cleanup; =20 - if (!(*parsedUri)->transport && - VIR_STRDUP((*parsedUri)->transport, "https") < 0) - goto cleanup; + if (!(*parsedUri)->transport) + (*parsedUri)->transport =3D g_strdup("https"); =20 result =3D 0; =20 diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 29b1b01b9b..a32f674740 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1034,8 +1034,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyT= ype **anyType) (*anyType)->value =3D (char *)xmlNodeListGetString(node->doc, node->children, 1); =20 - if (!(*anyType)->value && VIR_STRDUP((*anyType)->value, "") < 0) - goto failure; + if (!(*anyType)->value) + (*anyType)->value =3D g_strdup(""); =20 #define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \ do { \ diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index 73b32694a1..3b84713426 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -71,9 +71,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) } } =20 - if (!(*parsedUri)->transport && - VIR_STRDUP((*parsedUri)->transport, "https") < 0) - goto cleanup; + if (!(*parsedUri)->transport) + (*parsedUri)->transport =3D g_strdup("https"); =20 result =3D 0; =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index c9449ace9e..84f69da8de 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1307,8 +1307,8 @@ udevSetParent(struct udev_device *device, =20 } while (def->parent =3D=3D NULL && parent_device !=3D NULL); =20 - if (!def->parent && VIR_STRDUP(def->parent, "computer") < 0) - goto cleanup; + if (!def->parent) + def->parent =3D g_strdup("computer"); =20 ret =3D 0; =20 diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 3ce1556fc2..0377cea51a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3735,9 +3735,8 @@ virQEMUCapsLoadCache(virArch hostArch, =20 if (virXPathBoolean("boolean(./package)", ctxt) > 0) { qemuCaps->package =3D virXPathString("string(./package)", ctxt); - if (!qemuCaps->package && - VIR_STRDUP(qemuCaps->package, "") < 0) - goto cleanup; + if (!qemuCaps->package) + qemuCaps->package =3D g_strdup(""); } =20 if (virXPathBoolean("boolean(./kernelVersion)", ctxt) > 0) { diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3ef84cc9a6..ab13eebd39 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13339,9 +13339,8 @@ qemuDomainSetupDev(virQEMUDriverConfigPtr cfg, =20 mount_options =3D qemuSecurityGetMountOptions(mgr, vm->def); =20 - if (!mount_options && - VIR_STRDUP(mount_options, "") < 0) - goto cleanup; + if (!mount_options) + mount_options =3D g_strdup(""); =20 /* * tmpfs is limited to 64kb, since we only have device nodes in there diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bf301919cc..5b42bbfd48 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3574,8 +3574,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, } =20 /* ifname: check if it's set in newdev. If not, retain the autogenerat= ed one */ - if (!newdev->ifname && VIR_STRDUP(newdev->ifname, olddev->ifname) < 0) - goto cleanup; + if (!newdev->ifname) + newdev->ifname =3D 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 =3D g_strdup(olddev->info.alias); =20 /* device alias is checked already in virDomainDefCompatibleDevice */ =20 @@ -3617,9 +3616,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } =20 - if (!newdev->info.romfile && - VIR_STRDUP(newdev->info.romfile, olddev->info.romfile) < 0) - goto cleanup; + if (!newdev->info.romfile) + newdev->info.romfile =3D 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")); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9228c7d0ed..c22b257197 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1247,8 +1247,8 @@ doRemoteOpen(virConnectPtr conn, break; =20 case REMOTE_DRIVER_TRANSPORT_SSH: - if (!command && VIR_STRDUP(command, "ssh") < 0) - goto failed; + if (!command) + command =3D g_strdup("ssh"); =20 if (!(priv->client =3D virNetClientNewSSH(priv->hostname, port, diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index dd8f7d3808..82826d193c 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -459,8 +459,8 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr G_GN= UC_UNUSED, if (VIR_STRDUP(secdef->imagelabel, profile_name) < 0) goto err; =20 - if (!secdef->model && VIR_STRDUP(secdef->model, SECURITY_APPARMOR_NAME= ) < 0) - goto err; + if (!secdef->model) + secdef->model =3D g_strdup(SECURITY_APPARMOR_NAME); =20 /* Now that we have a label, load the profile into the kernel. */ if (load_profile(mgr, secdef->label, def, NULL, false) < 0) { diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 4988659044..c24a63afd6 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -938,9 +938,8 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr, if (!seclabel->imagelabel) goto cleanup; =20 - if (!seclabel->model && - VIR_STRDUP(seclabel->model, SECURITY_SELINUX_NAME) < 0) - goto cleanup; + if (!seclabel->model) + seclabel->model =3D g_strdup(SECURITY_SELINUX_NAME); =20 rc =3D 0; =20 @@ -3368,8 +3367,8 @@ virSecuritySELinuxGetSecurityMountOptions(virSecurity= ManagerPtr mgr, return NULL; } =20 - if (!opts && VIR_STRDUP(opts, "") < 0) - return NULL; + if (!opts) + opts =3D g_strdup(""); =20 VIR_DEBUG("imageLabel=3D%s opts=3D%s", secdef ? secdef->imagelabel : "(null)", opts); diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 5de21103f5..80d2dfd0b4 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -325,8 +325,8 @@ virStorageBackendLogicalMakeVol(char **const groups, vol->target.backingStore->type =3D VIR_STORAGE_TYPE_BLOCK; } =20 - if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0) - goto cleanup; + if (!vol->key) + vol->key =3D g_strdup(groups[2]); =20 if (virStorageBackendUpdateVolInfo(vol, false, VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < = 0) diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 6bfff9f5dd..75edab4b26 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -136,8 +136,8 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool, goto cleanup; } =20 - if (!volume->key && VIR_STRDUP(volume->key, tokens[0]) < 0) - goto cleanup; + if (!volume->key) + volume->key =3D g_strdup(tokens[0]); =20 if (volume->target.path =3D=3D NULL) { if (virAsprintf(&volume->target.path, "%s/%s", diff --git a/src/test/test_driver.c b/src/test/test_driver.c index bd095604c7..6af40ee35c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1100,8 +1100,8 @@ testOpenVolumesForPool(const char *file, return -1; } =20 - if (!volDef->key && VIR_STRDUP(volDef->key, volDef->target.path) <= 0) - return -1; + if (!volDef->key) + volDef->key =3D g_strdup(volDef->target.path); =20 if (virStoragePoolObjAddVol(obj, volDef) < 0) return -1; diff --git a/src/util/virfile.c b/src/util/virfile.c index 15713a58d9..6a26d4838c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -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 =3D g_strdup(p1); =20 ignore_value(virFileResolveLink(p2, &res2)); - if (!res2 && VIR_STRDUP(res2, p2) < 0) - return -1; + if (!res2) + res2 =3D g_strdup(p2); =20 return STREQ_NULLABLE(res1, res2); } diff --git a/src/util/virlease.c b/src/util/virlease.c index a49bd5b9fb..3d851eb808 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -106,12 +106,8 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arr= ay_new, /* This is an ipv6 lease */ if ((server_duid_tmp =3D 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 =3D g_strdup(server_duid_tmp); } else { /* Inject server-duid into those ipv6 leases which * didn't have it previously, for example, those diff --git a/src/util/virpci.c b/src/util/virpci.c index 2c54c8baa1..59a93a5e81 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -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 =3D g_strdup(entry->d_name); =20 continue; } diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index c2dadfd410..db440611dc 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -240,8 +240,8 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr = param, param->value.s =3D va_arg(ap, char *); } =20 - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - return -1; + if (!param->value.s) + param->value.s =3D g_strdup(""); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 7d20351a83..c9a80ba35d 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2659,8 +2659,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, = virDomainNetDefPtr *def) true) < 0) goto cleanup; =20 - if (!networkName && VIR_STRDUP(networkName, "") < 0) - goto cleanup; + if (!networkName) + networkName =3D g_strdup(""); } =20 /* vmx:vnet -> def:data.ifname */ diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index db14114cba..07bc99cc03 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -100,10 +100,8 @@ fillQemuCaps(virDomainCapsPtr domCaps, goto cleanup; } =20 - if (!domCaps->machine && - VIR_STRDUP(domCaps->machine, - virQEMUCapsGetPreferredMachine(qemuCaps)) < 0) - goto cleanup; + if (!domCaps->machine) + domCaps->machine =3D g_strdup(virQEMUCapsGetPreferredMachine(qemuC= aps)); =20 if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, false, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list