Fix false positives for null pointer on exit

This commit is contained in:
Richard Quirk 2011-11-23 21:19:54 +01:00
parent 2e08c8c5b1
commit d76657fec8
2 changed files with 15 additions and 0 deletions

View File

@ -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();

View File

@ -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)