shithub: choc

Download patch

ref: 8eda8d536064325a57d57efae613deb9ba015bf4
parent: f447ae17ddefc64f2bc803b5c3c81dceb7b59c68
author: Turo Lamminen <[email protected]>
date: Mon Feb 1 10:27:49 EST 2021

Refactor myargv and its contents to be owned by us

--- a/src/i_main.c
+++ b/src/i_main.c
@@ -18,6 +18,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -26,7 +27,9 @@
 #include "doomtype.h"
 #include "i_system.h"
 #include "m_argv.h"
+#include "m_misc.h"
 
+
 //
 // D_DoomMain()
 // Not a globally visible function, just included for source reference,
@@ -40,7 +43,13 @@
     // save arguments
 
     myargc = argc;
-    myargv = argv;
+    myargv = malloc(argc * sizeof(char *));
+    assert(myargv != NULL);
+
+    for (int i = 0; i < argc; i++)
+    {
+        myargv[i] = M_StringDuplicate(argv[i]);
+    }
 
     //!
     // Print the program version and exit.