Fixed #2689 (False positive: Possible null pointer dereference)
This commit is contained in:
parent
dd5e15b40c
commit
57056bcf61
|
@ -660,6 +660,14 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
if (indentlevel == 0)
|
if (indentlevel == 0)
|
||||||
break;
|
break;
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
|
|
||||||
|
if (null && indentlevel == 0)
|
||||||
|
{
|
||||||
|
// skip all "else" blocks because they are not executed in this execution path
|
||||||
|
while (Token::simpleMatch(tok2, "} else {"))
|
||||||
|
tok2 = tok2->tokAt(2)->link();
|
||||||
|
null = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch"))
|
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch"))
|
||||||
|
|
|
@ -1001,6 +1001,15 @@ private:
|
||||||
" wilma->Reload();\n"
|
" wilma->Reload();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void test(int *i) {\n"
|
||||||
|
" if(i == NULL) {\n"
|
||||||
|
" int b = 1;\n"
|
||||||
|
" } else {\n"
|
||||||
|
" int b = *i;\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test CheckNullPointer::nullConstantDereference
|
// Test CheckNullPointer::nullConstantDereference
|
||||||
|
|
Loading…
Reference in New Issue