Fix #647 (Crash during tokenizing (wrong) K&R function declaration)

http://sourceforge.net/apps/trac/cppcheck/ticket/647
Thanks to undingen for providing a patch
This commit is contained in:
Reijo Tomperi 2009-09-05 22:21:25 +03:00
parent 7af4ac4282
commit a3d9863725
2 changed files with 21 additions and 0 deletions

View File

@ -2279,6 +2279,14 @@ void Tokenizer::simplifyFunctionParameters()
break;
}
if (argumentNames.find(tok->str()) != argumentNames.end())
{
// Invalid code, two arguments with the same name.
// TODO, print error perhaps?
bailOut = true;
break;
}
argumentNames[tok->str()] = tok;
if (tok->next()->str() == ")")
{

View File

@ -111,6 +111,9 @@ private:
// Simplify nested strcat() calls
TEST_CASE(strcat1);
// Syntax error
TEST_CASE(argumentsWithSameName)
}
std::string tok(const char code[])
@ -1363,6 +1366,16 @@ private:
ASSERT_EQUALS(expect, tok(code));
}
void argumentsWithSameName()
{
// This code has syntax error, two variables can not have the same name
const char code[] = "void foo(x, x)\n"
" int x;\n"
" int x;\n"
"{}\n";
ASSERT_EQUALS("void foo ( x , x ) int x ; int x ; { }", tok(code));
}
};
REGISTER_TEST(TestSimplifyTokens)