Bug 1509929: Part 2 - Modify MakeCommandLine to accept an array of extra args that will be appended to the final result; r=mhowell
☠☠ backed out by d1efd32b03bf ☠ ☠
authorAaron Klotz <aklotz@mozilla.com>
Mon, 07 Jan 2019 22:36:33 +0000
changeset 509889 5ec50f23671ee8e8fcba3667e3b8b308a782c49f
parent 509888 8bdba9ec4d5b314313bb5f1b7b539011d7cea7d4
child 509890 8d432633f8fb15c6dc6008a4b9cccf79e5bb267f
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1509929
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509929: Part 2 - Modify MakeCommandLine to accept an array of extra args that will be appended to the final result; r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D15447
toolkit/xre/CmdLineAndEnvUtils.h
--- a/toolkit/xre/CmdLineAndEnvUtils.h
+++ b/toolkit/xre/CmdLineAndEnvUtils.h
@@ -291,40 +291,63 @@ inline wchar_t* ArgToString(wchar_t* d, 
 
   return d;
 }
 
 }  // namespace internal
 
 /**
  * Creates a command line from a list of arguments.
+ *
+ * @param argc Number of elements in |argv|
+ * @param argv Array of arguments
+ * @param aArgcExtra Number of elements in |aArgvExtra|
+ * @param aArgvExtra Optional array of arguments to be appended to the resulting
+ *                   command line after those provided by |argv|.
  */
-inline UniquePtr<wchar_t[]> MakeCommandLine(int argc, wchar_t** argv) {
+inline UniquePtr<wchar_t[]> MakeCommandLine(int argc, wchar_t** argv,
+                                            int aArgcExtra = 0,
+                                            wchar_t** aArgvExtra = nullptr) {
   int i;
   int len = 0;
 
-  // The + 1 of the last argument handles the allocation for null termination
+  // The + 1 for each argument reserves space for either a ' ' or the null
+  // terminator, depending on the position of the argument.
   for (i = 0; i < argc; ++i) {
     len += internal::ArgStrLen(argv[i]) + 1;
   }
 
+  for (i = 0; i < aArgcExtra; ++i) {
+    len += internal::ArgStrLen(aArgvExtra[i]) + 1;
+  }
+
   // Protect against callers that pass 0 arguments
   if (len == 0) {
     len = 1;
   }
 
   auto s = MakeUnique<wchar_t[]>(len);
   if (!s) {
     return s;
   }
 
+  int totalArgc = argc + aArgcExtra;
+
   wchar_t* c = s.get();
   for (i = 0; i < argc; ++i) {
     c = internal::ArgToString(c, argv[i]);
-    if (i + 1 != argc) {
+    if (i + 1 != totalArgc) {
+      *c = ' ';
+      ++c;
+    }
+  }
+
+  for (i = 0; i < aArgcExtra; ++i) {
+    c = internal::ArgToString(c, aArgvExtra[i]);
+    if (i + 1 != aArgcExtra) {
       *c = ' ';
       ++c;
     }
   }
 
   *c = '\0';
 
   return s;