]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virQEMUBuildCommandLineJSONIterate: Simplify logic
authorPeter Krempa <pkrempa@redhat.com>
Sat, 25 Sep 2021 07:01:52 +0000 (09:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:26:01 +0000 (10:26 +0200)
With automatic memory freeing we can simplify the function to avoid two
almost-identical calls to virQEMUBuildCommandLineJSONRecurse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virqemu.c

index e31451dff4f28e796c3b78eb8d6dcd4a9f803c42..3e9311e3c7583fbea51dfc15a28136480e02f2f8 100644 (file)
@@ -158,23 +158,17 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
                                    void *opaque)
 {
     struct virQEMUCommandLineJSONIteratorData *data = opaque;
+    g_autofree char *tmpkey = NULL;
 
     if (STREQ_NULLABLE(key, data->skipKey))
         return 0;
 
-    if (data->prefix) {
-        g_autofree char *tmpkey = NULL;
+    if (data->prefix)
+        key = tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
 
-        tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
-
-        return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
-                                                  data->skipKey,
-                                                  data->arrayFunc, false);
-    } else {
-        return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
-                                                  data->skipKey,
-                                                  data->arrayFunc, false);
-    }
+    return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
+                                              data->skipKey,
+                                              data->arrayFunc, false);
 }