]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use g_strdup where VIR_STRDUP's return value was propagated
authorJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 10:55:05 +0000 (12:55 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 21 Oct 2019 10:51:55 +0000 (12:51 +0200)
All the callers of these functions only check for a negative
return value.

However, virNetDevOpenvswitchGetVhostuserIfname is documented
as returning 1 for openvswitch interfaces so preserve that.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
13 files changed:
src/esx/esx_vi.c
src/esx/esx_vi_types.c
src/qemu/qemu_alias.c
src/qemu/qemu_monitor_json.c
src/storage/storage_util.c
src/util/vircgroupv2.c
src/util/viriscsi.c
src/util/virnuma.c
src/util/virresctrl.c
src/util/virstoragefile.c
src/util/viruri.c
tests/qemuxml2argvmock.c
tests/securityselinuxhelper.c

index 004434c45423b8719bb64f431aea370442e3af84..ef37bbf88d8a752e62a04eba65b13d279abbcbd0 100644 (file)
@@ -2388,7 +2388,8 @@ esxVI_GetVirtualMachineMORef(esxVI_ObjectContent *virtualMachine,
         if (virtualMachine->obj &&
             STREQ(virtualMachine->obj->type, "VirtualMachine") &&
             virtualMachine->obj->value) {
-            return VIR_STRDUP(*moref, virtualMachine->obj->value);
+            *moref = g_strdup(virtualMachine->obj->value);
+            return 0;
         }
     }
     return -1;
index deb6ebd09fb02bfffd5c82630c6416e3e17692a9..29b1b01b9bf32ed01e305238d5fa7e101c4696cc 100644 (file)
@@ -1206,10 +1206,8 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
 {
     ESX_VI_CHECK_ARG_LIST(dest);
 
-    if (!src)
-        return 0;
-
-    return VIR_STRDUP(*dest, src);
+    *dest = g_strdup(src);
+    return 0;
 }
 
 /* esxVI_String_CastFromAnyType */
index 5af3725bf5e3f808d85aa8938f91e50df31e6b20..d4d8eb4252e7dda80c6082b6d28117d2c90ee38f 100644 (file)
@@ -134,7 +134,8 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
              * hardcoded the name of their single PCI controller as
              * "pci".
              */
-            return VIR_STRDUP(controller->info.alias, "pci");
+            controller->info.alias = g_strdup("pci");
+            return 0;
         } else if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) {
             /* The pcie-root controller on Q35 machinetypes uses a
              * different naming convention ("pcie.0"), because it is
@@ -153,18 +154,24 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
          * controller hardcoded with id "ide"
          */
         if (qemuDomainHasBuiltinIDE(domainDef) &&
-            controller->idx == 0)
-            return VIR_STRDUP(controller->info.alias, "ide");
+            controller->idx == 0) {
+            controller->info.alias = g_strdup("ide");
+            return 0;
+        }
     } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA) {
         /* for any Q35 machine, the first SATA controller is the
          * integrated one, and it too is hardcoded with id "ide"
          */
-        if (qemuDomainIsQ35(domainDef) && controller->idx == 0)
-            return VIR_STRDUP(controller->info.alias, "ide");
+        if (qemuDomainIsQ35(domainDef) && controller->idx == 0) {
+            controller->info.alias = g_strdup("ide");
+            return 0;
+        }
     } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
         /* first USB device is "usb", others are normal "usb%d" */
-        if (controller->idx == 0)
-            return VIR_STRDUP(controller->info.alias, "usb");
+        if (controller->idx == 0) {
+            controller->info.alias = g_strdup("usb");
+            return 0;
+        }
     }
     /* all other controllers use the default ${type}${index} naming
      * scheme for alias/id.
index 4b765da0b14fc79ba75b00c8ab7ff622ca3ecd68..602a0380d74a9ee7b1d418c3bd5b633caf82f436 100644 (file)
@@ -5957,7 +5957,8 @@ qemuMonitorJSONGetCPUModelComparison(qemuMonitorPtr mon,
         return -1;
     }
 
-    return VIR_STRDUP(*result, data_result);
+    *result = g_strdup(data_result);
+    return 0;
 }
 
 
index a4c8a5e971a16edafb5dad5f938f76a13a3f6f59..692b3e7a9d60fbe72fb8ee11a1d55c8ce809f012 100644 (file)
@@ -2072,7 +2072,8 @@ virStorageBackendVolCreateLocal(virStoragePoolObjPtr pool,
     }
 
     VIR_FREE(vol->key);
-    return VIR_STRDUP(vol->key, vol->target.path);
+    vol->key = g_strdup(vol->target.path);
+    return 0;
 }
 
 
index 621ab71eb55c9c90fda73e65009310ddd7bc6248..7a64e74c3a617d6b6ac1b4b45a813c65f7c61215 100644 (file)
@@ -146,7 +146,8 @@ static int
 virCgroupV2CopyMounts(virCgroupPtr group,
                       virCgroupPtr parent)
 {
-    return VIR_STRDUP(group->unified.mountPoint, parent->unified.mountPoint);
+    group->unified.mountPoint = g_strdup(parent->unified.mountPoint);
+    return 0;
 }
 
 
@@ -189,7 +190,8 @@ virCgroupV2DetectMounts(virCgroupPtr group,
 
     VIR_FREE(group->unified.mountPoint);
 
-    return VIR_STRDUP(group->unified.mountPoint, mntDir);
+    group->unified.mountPoint = g_strdup(mntDir);
+    return 0;
 }
 
 
index dc553e775239d4f65d65ecf5e76f3291ab248749..1b143ec61f3442d5f68b530414195f667ce58899 100644 (file)
@@ -60,8 +60,10 @@ virISCSIExtractSession(char **const groups,
     struct virISCSISessionData *data = opaque;
 
     if (!data->session &&
-        STREQ(groups[1], data->devpath))
-        return VIR_STRDUP(data->session, groups[0]);
+        STREQ(groups[1], data->devpath)) {
+        data->session = g_strdup(groups[0]);
+        return 0;
+    }
     return 0;
 }
 
index 8f50634c2a06a55f7b28f7dbbb38f7b0f2aae3e2..448833d8d1ab1ea4504976e90c75be4368dd3680 100644 (file)
@@ -579,7 +579,8 @@ static int
 virNumaGetHugePageInfoDir(char **path, int node)
 {
     if (node == -1) {
-        return VIR_STRDUP(*path, HUGEPAGES_SYSTEM_PREFIX);
+        *path = g_strdup(HUGEPAGES_SYSTEM_PREFIX);
+        return 0;
     } else {
         return virAsprintf(path,
                            HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
index ab650b59b9afbd5c5f2b1b9b75266222e6a8585c..e52408ed06d2c1e96d70746d636a60b8eb55f930 100644 (file)
@@ -1388,7 +1388,8 @@ virResctrlSetID(char **resctrlid,
         return -1;
     }
 
-    return VIR_STRDUP(*resctrlid, id);
+    *resctrlid = g_strdup(id);
+    return 0;
 }
 
 
index 64e09d79511c94c7876163f92035c3a98758a5ad..c13ed9fee5522ddbf9148d7fa9923acf91d99cb7 100644 (file)
@@ -4468,7 +4468,8 @@ int
 virStorageSourceInitiatorCopy(virStorageSourceInitiatorDefPtr dest,
                               const virStorageSourceInitiatorDef *src)
 {
-    return VIR_STRDUP(dest->iqn, src->iqn);
+    dest->iqn = g_strdup(src->iqn);
+    return 0;
 }
 
 void
index a43fe2afd4811fd80546396b94761e68a7c3673a..af2e828c2856a21c364440532335d9e4326d90ad 100644 (file)
@@ -350,7 +350,8 @@ virURIFindAliasMatch(char *const*aliases, const char *alias,
             STREQLEN(*aliases, alias, alias_len)) {
             VIR_DEBUG("Resolved alias '%s' to '%s'",
                       alias, offset+1);
-            return VIR_STRDUP(*uri, offset+1);
+            *uri = g_strdup(offset + 1);
+            return 0;
         }
 
         aliases++;
index 2b9e5e7a492429ee4936cde71f39689a61a12e50..34e0eb91a6a76e149df8cb901c698868738d9e86 100644 (file)
@@ -153,7 +153,8 @@ virNetDevTapCreate(char **ifname,
         return 0;
     } else {
         VIR_FREE(*ifname);
-        return VIR_STRDUP(*ifname, "vnet0");
+        *ifname = g_strdup("vnet0");
+        return 0;
     }
 }
 
@@ -229,7 +230,8 @@ int
 virNetDevOpenvswitchGetVhostuserIfname(const char *path G_GNUC_UNUSED,
                                        char **ifname)
 {
-    return VIR_STRDUP(*ifname, "vhost-user0");
+    *ifname = g_strdup("vhost-user0");
+    return 1;
 }
 
 int
index 6391f67360b2199ad576b11681a320527ebae412..814250b73110d64b2f7d88747554a842abf4d9d9 100644 (file)
@@ -111,7 +111,8 @@ int getcon_raw(security_context_t *context)
         errno = EINVAL;
         return -1;
     }
-    return VIR_STRDUP_QUIET(*context, getenv("FAKE_SELINUX_CONTEXT"));
+    *context = g_strdup(getenv("FAKE_SELINUX_CONTEXT"));
+    return 0;
 }
 
 int getcon(security_context_t *context)
@@ -135,7 +136,8 @@ int getpidcon_raw(pid_t pid, security_context_t *context)
         errno = EINVAL;
         return -1;
     }
-    return VIR_STRDUP_QUIET(*context, getenv("FAKE_SELINUX_CONTEXT"));
+    *context = g_strdup(getenv("FAKE_SELINUX_CONTEXT"));
+    return 0;
 }
 
 int getpidcon(pid_t pid, security_context_t *context)