bug fix
authorroot <root@plrg-1.ics.uci.edu>
Sat, 7 Dec 2019 00:54:32 +0000 (16:54 -0800)
committerroot <root@plrg-1.ics.uci.edu>
Sat, 7 Dec 2019 00:54:32 +0000 (16:54 -0800)
main.cc

diff --git a/main.cc b/main.cc
index 9ed1bc6cd35de7bef9ecfadc538ec1854f825822..984d0a317ffc43dd7b095a3fa870c3171bb09e31 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -101,17 +101,23 @@ void parse_options(struct model_params *params) {
        if (options == NULL)
                return;
        int argc = 1;
-       for(int index = 0;options[index]!=0;index++) {
+       int index;
+       for(index = 0;options[index]!=0;index++) {
                if (options[index] == ' ')
                        argc++;
        }
        argc++; //first parameter is executable name
+       char optcpy[index + 1];
+       memcpy(optcpy, options, index+1);
        char * argv[argc + 1];
        argv[0] = NULL;
-       argv[1] = options;
-       for(int index = 0, count = 2;options[index]!=0;index++) {
-               if (options[index]==' ')
-                       argv[count++] = &options[index];
+       argv[1] = optcpy;
+       int count = 2;
+       for(index = 0;optcpy[index]!=0;index++) {
+               if (optcpy[index] == ' ') {
+                       argv[count++] = &optcpy[index+1];
+                       optcpy[index] = 0;
+               }
        }
 
        while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {