fix a serious symbol database bug where parts of a function could be skipped

This commit is contained in:
Robert Reif 2011-08-23 20:12:29 -04:00
parent 2f0fc9444f
commit 6f3131da8c
2 changed files with 11 additions and 1 deletions

View File

@ -591,7 +591,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
else if (tok->str() == "{")
{
if (!Token::Match(tok->previous(), "=|,|{"))
if (!Token::Match(tok->previous(), "=|,"))
{
scopeList.push_back(Scope(this, tok, scope, Scope::eUnconditional, tok));
scope = &scopeList.back();

View File

@ -41,6 +41,7 @@ private:
TEST_CASE(zeroDiv2);
TEST_CASE(zeroDiv3);
TEST_CASE(zeroDiv4);
TEST_CASE(zeroDiv5);
TEST_CASE(sprintf1); // Dangerous usage of sprintf
TEST_CASE(sprintf2);
@ -354,6 +355,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void zeroDiv5()
{
check("void f()\n"
"{ { {\n"
" long a = b / 0;\n"
"} } }\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str());
}
void sprintfUsage(const char code[])
{