Commit 9978fae6 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Ensure removing processed command line arguments.

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

Review URL: https://chromiumcodereview.appspot.com/10534137

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11803 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ce6aa5c2
......@@ -343,6 +343,7 @@ static Flag* FindFlag(const char* name) {
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 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
} else {
fprintf(stderr, "Error: unrecognized flag %s\n"
"Try --help for options\n", arg);
return j;
return_code = j;
break;
}
}
......@@ -382,7 +384,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
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 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
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 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
exit(0);
}
// parsed all flags successfully
return 0;
return return_code;
}
......
......@@ -159,7 +159,7 @@ TEST(Flags6) {
CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
const_cast<char **>(argv),
true));
CHECK_EQ(4, argc);
CHECK_EQ(2, argc);
}
......@@ -232,3 +232,16 @@ TEST(FlagsJSArguments4) {
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment