Fix false positives for null pointer on exit
This commit is contained in:
parent
2e08c8c5b1
commit
d76657fec8
|
@ -809,6 +809,10 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
break;
|
||||
}
|
||||
|
||||
if (Token::Match(tok2, "exit ( %num% ) ;")) {
|
||||
break;
|
||||
}
|
||||
|
||||
// parameters to sizeof are not dereferenced
|
||||
if (Token::Match(tok2, "decltype|sizeof (")) {
|
||||
tok2 = tok2->next()->link();
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
TEST_CASE(nullpointer_in_typeid);
|
||||
TEST_CASE(nullpointer_in_for_loop);
|
||||
TEST_CASE(nullpointerDelete);
|
||||
TEST_CASE(nullpointerExit);
|
||||
}
|
||||
|
||||
void check(const char code[], bool inconclusive = false, bool cpp11 = false) {
|
||||
|
@ -1607,6 +1608,16 @@ private:
|
|||
"}\n", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointerExit() {
|
||||
check("void f() {\n"
|
||||
" K *k = getK();\n"
|
||||
" if (!k)\n"
|
||||
" exit(1);\n"
|
||||
" k->f();\n"
|
||||
"}\n", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestNullPointer)
|
||||
|
|
Loading…
Reference in New Issue