Fixed #1395 (false positive: Possible null pointer dereference)
This commit is contained in:
parent
ccef1d6eb5
commit
e4cc8cf1a0
|
@ -4606,6 +4606,8 @@ 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.
|
||||||
|
if (tok3->previous()->link() &&
|
||||||
|
!Token::simpleMatch(tok3->previous()->link()->previous(), "if"))
|
||||||
bailOutFromLoop = tok3->link();
|
bailOutFromLoop = tok3->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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