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) { ...@@ -343,6 +343,7 @@ static Flag* FindFlag(const char* name) {
int FlagList::SetFlagsFromCommandLine(int* argc, int FlagList::SetFlagsFromCommandLine(int* argc,
char** argv, char** argv,
bool remove_flags) { bool remove_flags) {
int return_code = 0;
// parse arguments // parse arguments
for (int i = 1; i < *argc;) { for (int i = 1; i < *argc;) {
int j = i; // j > 0 int j = i; // j > 0
...@@ -368,7 +369,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -368,7 +369,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
} else { } else {
fprintf(stderr, "Error: unrecognized flag %s\n" fprintf(stderr, "Error: unrecognized flag %s\n"
"Try --help for options\n", arg); "Try --help for options\n", arg);
return j; return_code = j;
break;
} }
} }
...@@ -382,7 +384,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -382,7 +384,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
fprintf(stderr, "Error: missing value for flag %s of type %s\n" fprintf(stderr, "Error: missing value for flag %s of type %s\n"
"Try --help for options\n", "Try --help for options\n",
arg, Type2String(flag->type())); arg, Type2String(flag->type()));
return j; return_code = j;
break;
} }
} }
...@@ -424,7 +427,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -424,7 +427,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
fprintf(stderr, "Error: illegal value for flag %s of type %s\n" fprintf(stderr, "Error: illegal value for flag %s of type %s\n"
"Try --help for options\n", "Try --help for options\n",
arg, Type2String(flag->type())); arg, Type2String(flag->type()));
return j; return_code = j;
break;
} }
// remove the flag & value from the command // remove the flag & value from the command
...@@ -451,7 +455,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -451,7 +455,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
exit(0); exit(0);
} }
// parsed all flags successfully // parsed all flags successfully
return 0; return return_code;
} }
......
...@@ -159,7 +159,7 @@ TEST(Flags6) { ...@@ -159,7 +159,7 @@ TEST(Flags6) {
CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
const_cast<char **>(argv), const_cast<char **>(argv),
true)); true));
CHECK_EQ(4, argc); CHECK_EQ(2, argc);
} }
...@@ -232,3 +232,16 @@ TEST(FlagsJSArguments4) { ...@@ -232,3 +232,16 @@ TEST(FlagsJSArguments4) {
CHECK_EQ(0, FLAG_js_arguments.argc()); 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