Improve checking -D arguments for command line.

This commit is contained in:
Kimmo Varis 2011-01-17 21:19:27 +02:00
parent 6dd16d3919
commit bd5e9e5309
2 changed files with 23 additions and 1 deletions

View File

@ -231,11 +231,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (strcmp(argv[i], "-D") == 0)
{
++i;
if (i >= argc)
if (i >= argc || strncmp(argv[i], "-", 1) == 0 ||
strncmp(argv[i], "--", 2) == 0)
{
PrintMessage("cppcheck: argument to '-D' is missing");
return false;
}
define = argv[i];
}
// "-Ddefine"

View File

@ -47,6 +47,8 @@ private:
TEST_CASE(quietshort);
TEST_CASE(quietlong);
TEST_CASE(defines_noarg);
TEST_CASE(defines_noarg2);
TEST_CASE(defines_noarg3);
TEST_CASE(defines);
TEST_CASE(defines2);
TEST_CASE(defines3);
@ -240,6 +242,24 @@ private:
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
}
void defines_noarg2()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
}
void defines_noarg3()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
}
void defines()
{
REDIRECT;