Revision: 11803
Author:   [email protected]
Date:     Wed Jun 13 08:02:05 2012
Log:      Ensure removing processed command line arguments.

BUG="d8 --crankshaft --expose-debug-as" crashes
TEST=test-flags/FlagsRemoveIncomplete

Review URL: https://chromiumcodereview.appspot.com/10534137
http://code.google.com/p/v8/source/detail?r=11803

Modified:
 /branches/bleeding_edge/src/flags.cc
 /branches/bleeding_edge/test/cctest/test-flags.cc

=======================================
--- /branches/bleeding_edge/src/flags.cc        Mon Mar 12 06:56:56 2012
+++ /branches/bleeding_edge/src/flags.cc        Wed Jun 13 08:02:05 2012
@@ -343,6 +343,7 @@
 int FlagList::SetFlagsFromCommandLine(int* argc,
                                       char** argv,
                                       bool remove_flags) {
+  int return_code = 0;
   // parse arguments
   for (int i = 1; i < *argc;) {
     int j = i;  // j > 0
@@ -368,7 +369,8 @@
         } else {
           fprintf(stderr, "Error: unrecognized flag %s\n"
                   "Try --help for options\n", arg);
-          return j;
+          return_code = j;
+          break;
         }
       }

@@ -382,7 +384,8 @@
           fprintf(stderr, "Error: missing value for flag %s of type %s\n"
                   "Try --help for options\n",
                   arg, Type2String(flag->type()));
-          return j;
+          return_code = j;
+          break;
         }
       }

@@ -424,7 +427,8 @@
         fprintf(stderr, "Error: illegal value for flag %s of type %s\n"
                 "Try --help for options\n",
                 arg, Type2String(flag->type()));
-        return j;
+        return_code = j;
+        break;
       }

       // remove the flag & value from the command
@@ -451,7 +455,7 @@
     exit(0);
   }
   // parsed all flags successfully
-  return 0;
+  return return_code;
 }


=======================================
--- /branches/bleeding_edge/test/cctest/test-flags.cc Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/cctest/test-flags.cc Wed Jun 13 08:02:05 2012
@@ -159,7 +159,7 @@
   CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
                                                 const_cast<char **>(argv),
                                                 true));
-  CHECK_EQ(4, argc);
+  CHECK_EQ(2, argc);
 }


@@ -232,3 +232,16 @@
   CHECK_EQ(0, FLAG_js_arguments.argc());
 }

+
+TEST(FlagsRemoveIncomplete) {
+  // Test that processed command line arguments are removed, even
+  // if the list of arguments ends unexpectedly.
+  SetFlagsToDefault();
+  int argc = 3;
+  const char* argv[] = { "", "--crankshaft", "--expose-debug-as" };
+  CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc,
+                                                const_cast<char **>(argv),
+                                                true));
+  CHECK_NE(NULL, argv[1]);
+  CHECK_EQ(argc, 2);
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to