]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
protect_argv(): Only set return variable in success case
authorRalf Habacker <ralf.habacker@freenet.de>
Sat, 4 Dec 2021 12:53:10 +0000 (13:53 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Mon, 6 Dec 2021 10:09:20 +0000 (10:09 +0000)
This avoids overwriting the variable even if there is no result.

dbus/dbus-spawn-win.c

index 86e5324c8c629b733294dc46295133fc0c95fda6..6037b9d16b41b14a0e6540ad6df7b813e596204c 100644 (file)
@@ -368,15 +368,16 @@ protect_argv (char  * const *argv,
 {
   int i;
   int argc = 0;
+  char **args = NULL;
 
   while (argv[argc])
     ++argc;
-  *new_argv = dbus_malloc ((argc + 1) * sizeof (char *));
-  if (*new_argv == NULL)
+  args = dbus_malloc ((argc + 1) * sizeof (char *));
+  if (args == NULL)
     return -1;
 
   for (i = 0; i < argc; i++)
-    (*new_argv)[i] = NULL;
+    (args)[i] = NULL;
 
   /* Quote each argv element if necessary, so that it will get
    * reconstructed correctly in the C runtime startup code.  Note that
@@ -413,7 +414,7 @@ protect_argv (char  * const *argv,
           p++;
         }
 
-      q = (*new_argv)[i] = dbus_malloc (len + need_dblquotes*2 + 1);
+      q = args[i] = dbus_malloc (len + need_dblquotes*2 + 1);
 
       if (q == NULL)
         return -1;
@@ -443,9 +444,10 @@ protect_argv (char  * const *argv,
       if (need_dblquotes)
         *q++ = '"';
       *q++ = '\0';
-      /* printf ("argv[%d]:%s, need_dblquotes:%s len:%d => %s\n", i, argv[i], need_dblquotes?"TRUE":"FALSE", len, (*new_argv)[i]); */
+      /* printf ("argv[%d]:%s, need_dblquotes:%s len:%d => %s\n", i, argv[i], need_dblquotes?"TRUE":"FALSE", len, (args)[i]); */
     }
-  (*new_argv)[argc] = NULL;
+  args[argc] = NULL;
+  *new_argv = args;
 
   return argc;
 }