Fixed #1395 (false positive: Possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2010-02-20 15:50:44 +01:00
parent ccef1d6eb5
commit e4cc8cf1a0
2 changed files with 19 additions and 1 deletions

View File

@ -4606,7 +4606,9 @@ bool Tokenizer::simplifyKnownVariables()
else if (tok3->str() == "{" && tok3->previous()->str() == ")")
{
// There is a possible loop after the assignment. Try to skip it.
bailOutFromLoop = tok3->link();
if (tok3->previous()->link() &&
!Token::simpleMatch(tok3->previous()->link()->previous(), "if"))
bailOutFromLoop = tok3->link();
continue;
}
else if (tok3->str() == "}" && tok3->link() && tok3->link()->previous()->str() == ")")

View File

@ -98,6 +98,7 @@ private:
TEST_CASE(simplifyKnownVariables17);
TEST_CASE(simplifyKnownVariables18);
TEST_CASE(simplifyKnownVariables19);
TEST_CASE(simplifyKnownVariables20);
TEST_CASE(match1);
@ -1041,6 +1042,21 @@ private:
simplifyKnownVariables(code));
}
void simplifyKnownVariables20()
{
const char code[] = "void f()\n"
"{\n"
" int i = 0;\n"
" if (x) {\n"
" if (i) i=0;\n"
" }\n"
"}\n";
ASSERT_EQUALS(
"void f ( ) { int i ; i = 0 ; if ( x ) { if ( 0 ) { i = 0 ; } } }",
simplifyKnownVariables(code));
}
void match1()
{
// Match "%var% | %var%"