]> xenbits.xensource.com Git - libvirt.git/commitdiff
src: Avoid needless checks before calling g_strdup()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Sep 2023 09:28:31 +0000 (11:28 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Sep 2023 12:46:24 +0000 (14:46 +0200)
There are few places where the following pattern occurs:

  if (var)
      other = g_strdup(var);

where @other wasn't initialized before g_strdup(). Checking for
var != NULL is useless in this case, as that's exactly what
g_strdup() does (in which case it returns NULL).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_event.c
src/libxl/libxl_conf.c
src/lxc/lxc_native.c
src/qemu/qemu_monitor_json.c
src/util/virconf.c

index 75603a933a13b5d9bf6aefee28bff19649201f80..09f3368064a31753d597f99965d2ad6533e60983 100644 (file)
@@ -1561,8 +1561,7 @@ virDomainEventMetadataChangeNew(int id,
         return NULL;
 
     ev->type = type;
-    if (nsuri)
-        ev->nsuri = g_strdup(nsuri);
+    ev->nsuri = g_strdup(nsuri);
 
     return (virObjectEvent *)ev;
 }
index 3ffb46fddd848aedf8743b784799e6f1c218c1fe..4582126d19c1695e285dbff0327511f7c2ac9e49 100644 (file)
@@ -583,8 +583,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
 #endif
 
         /* copy SLIC table path to acpi_firmware */
-        if (def->os.slic_table)
-            b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
+        b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
 
         if (def->nsounds > 0) {
             /*
@@ -1198,8 +1197,7 @@ libxlMakeDisk(virDomainDiskDef *l_disk, libxl_device_disk *x_disk)
         return -1;
     }
 
-    if (l_disk->domain_name)
-        x_disk->backend_domname = g_strdup(l_disk->domain_name);
+    x_disk->backend_domname = g_strdup(l_disk->domain_name);
 
     return 0;
 }
index 5a63efc35fd59fb3fac950e4e9802096d39fa35b..c0011e06006d4d340e19d572de756463d8403367 100644 (file)
@@ -67,8 +67,7 @@ lxcCreateFSDef(int type,
 
     def->type = type;
     def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
-    if (src)
-        def->src->path = g_strdup(src);
+    def->src->path = g_strdup(src);
     def->dst = g_strdup(dst);
     def->readonly = readonly;
     def->usage = usage;
index 137cb4e293976efc49b8f9fe2b10d38f046103c4..8152eea9a0774c70731489b62ab529e49d3dbf8b 100644 (file)
@@ -2960,8 +2960,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValue *reply,
     case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
         if (error) {
             tmp = virJSONValueObjectGetString(ret, "error-desc");
-            if (tmp)
-                *error = g_strdup(tmp);
+            *error = g_strdup(tmp);
         }
         break;
 
index 934632a35fe8fc58fdefa6b296753610e5a7e8df..8fdf40e9d0e271aa5f3d34d5a22c24153c1ebc6b 100644 (file)
@@ -939,8 +939,7 @@ int virConfGetValueStringList(virConf *conf,
     case VIR_CONF_STRING:
         if (compatString) {
             *values = g_new0(char *, cval->str ? 2 : 1);
-            if (cval->str)
-                (*values)[0] = g_strdup(cval->str);
+            (*values)[0] = g_strdup(cval->str);
             break;
         }
         G_GNUC_FALLTHROUGH;