Fixed #1795 (false positive: nullpointer dereference (needs to improve Tokenizer::simplifyKnownVariables))

This commit is contained in:
Daniel Marjamäki 2010-06-19 17:54:38 +02:00
parent 82b63dd736
commit 85bf4b2be6
2 changed files with 22 additions and 5 deletions

View File

@ -5490,11 +5490,6 @@ bool Tokenizer::simplifyKnownVariables()
bailOutFromLoop = tok3->link();
continue;
}
else if (tok3->str() == "}" && tok3->link() && tok3->link()->previous()->str() == ")")
{
// Assignment was in the middle of possible loop, bail out.
break;
}
// Variable used in realloc (see Ticket #1649)
if (Token::Match(tok3, "%var% = realloc ( %var% ,") &&

View File

@ -110,6 +110,7 @@ private:
TEST_CASE(simplifyKnownVariables25);
TEST_CASE(simplifyKnownVariables26);
TEST_CASE(simplifyKnownVariables27);
TEST_CASE(simplifyKnownVariables28);
TEST_CASE(match1);
@ -1336,6 +1337,27 @@ private:
simplifyKnownVariables(code));
}
void simplifyKnownVariables28()
{
const char code[] = "void foo(int g)\n"
"{\n"
" int i = 2;\n"
" if (g) {\n"
" }\n"
" if (i > 0) {\n"
" }\n"
"}\n";
ASSERT_EQUALS(
"void foo ( int g ) "
"{"
" int i ; i = 2 ;"
" if ( g ) { }"
" if ( 0 < 2 ) { } "
"}",
simplifyKnownVariables(code));
}
void match1()
{
// Match "%var% | %var%"