Fix 11416: FP nullPointerRedundantCheck for check after loop with break (#4620)
This commit is contained in:
parent
4103d05c7f
commit
663a8411dd
|
@ -281,6 +281,8 @@ struct ReverseTraversal {
|
||||||
const bool inLoop = condTok->astTop() && Token::Match(condTok->astTop()->previous(), "for|while (");
|
const bool inLoop = condTok->astTop() && Token::Match(condTok->astTop()->previous(), "for|while (");
|
||||||
// Evaluate condition of for and while loops first
|
// Evaluate condition of for and while loops first
|
||||||
if (inLoop) {
|
if (inLoop) {
|
||||||
|
if (Token::findmatch(tok->link(), "goto|break", tok))
|
||||||
|
break;
|
||||||
if (condAction.isModified())
|
if (condAction.isModified())
|
||||||
break;
|
break;
|
||||||
valueFlowGenericForward(condTok, analyzer, settings);
|
valueFlowGenericForward(condTok, analyzer, settings);
|
||||||
|
|
|
@ -139,6 +139,7 @@ private:
|
||||||
TEST_CASE(nullpointer93); // #3929
|
TEST_CASE(nullpointer93); // #3929
|
||||||
TEST_CASE(nullpointer94); // #11040
|
TEST_CASE(nullpointer94); // #11040
|
||||||
TEST_CASE(nullpointer95); // #11142
|
TEST_CASE(nullpointer95); // #11142
|
||||||
|
TEST_CASE(nullpointer96); // #11416
|
||||||
TEST_CASE(nullpointer_addressOf); // address of
|
TEST_CASE(nullpointer_addressOf); // address of
|
||||||
TEST_CASE(nullpointerSwitch); // #2626
|
TEST_CASE(nullpointerSwitch); // #2626
|
||||||
TEST_CASE(nullpointer_cast); // #4692
|
TEST_CASE(nullpointer_cast); // #4692
|
||||||
|
@ -2763,6 +2764,25 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nullpointer96()
|
||||||
|
{
|
||||||
|
check("struct S {\n"
|
||||||
|
" int x;\n"
|
||||||
|
"};\n"
|
||||||
|
"S *create_s();\n"
|
||||||
|
"void test() {\n"
|
||||||
|
" S *s = create_s();\n"
|
||||||
|
" for (int i = 0; i < s->x; i++) {\n"
|
||||||
|
" if (s->x == 17) {\n"
|
||||||
|
" s = nullptr;\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
" if (s) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void nullpointer_addressOf() { // address of
|
void nullpointer_addressOf() { // address of
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" struct X *x = 0;\n"
|
" struct X *x = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue