Fixed #1395 (false positive: Possible null pointer dereference)
This commit is contained in:
parent
ccef1d6eb5
commit
e4cc8cf1a0
|
@ -4606,7 +4606,9 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
else if (tok3->str() == "{" && tok3->previous()->str() == ")")
|
else if (tok3->str() == "{" && tok3->previous()->str() == ")")
|
||||||
{
|
{
|
||||||
// There is a possible loop after the assignment. Try to skip it.
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
else if (tok3->str() == "}" && tok3->link() && tok3->link()->previous()->str() == ")")
|
else if (tok3->str() == "}" && tok3->link() && tok3->link()->previous()->str() == ")")
|
||||||
|
|
|
@ -98,6 +98,7 @@ private:
|
||||||
TEST_CASE(simplifyKnownVariables17);
|
TEST_CASE(simplifyKnownVariables17);
|
||||||
TEST_CASE(simplifyKnownVariables18);
|
TEST_CASE(simplifyKnownVariables18);
|
||||||
TEST_CASE(simplifyKnownVariables19);
|
TEST_CASE(simplifyKnownVariables19);
|
||||||
|
TEST_CASE(simplifyKnownVariables20);
|
||||||
|
|
||||||
TEST_CASE(match1);
|
TEST_CASE(match1);
|
||||||
|
|
||||||
|
@ -1041,6 +1042,21 @@ private:
|
||||||
simplifyKnownVariables(code));
|
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()
|
void match1()
|
||||||
{
|
{
|
||||||
// Match "%var% | %var%"
|
// Match "%var% | %var%"
|
||||||
|
|
Loading…
Reference in New Issue