Fixed #2193 (false negative: nullpointer dereference)
This commit is contained in:
parent
0fffa1f651
commit
a8d7ac0f0d
|
@ -491,8 +491,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
}
|
||||
|
||||
// abort function..
|
||||
if (Token::Match(tok2->previous(), "[;{}] %var% (") &&
|
||||
Token::simpleMatch(tok2->next()->link(), ") ; }"))
|
||||
if (Token::simpleMatch(tok2, ") ; }") &&
|
||||
Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% ("))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ private:
|
|||
TEST_CASE(nullpointer7);
|
||||
TEST_CASE(nullpointer8);
|
||||
TEST_CASE(nullpointer9);
|
||||
TEST_CASE(checkAndDeRef); // check if pointer is null and then dereference it
|
||||
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
|
||||
}
|
||||
|
||||
void check(const char code[])
|
||||
|
@ -639,7 +639,7 @@ private:
|
|||
}
|
||||
|
||||
// Check if pointer is null and the dereference it
|
||||
void checkAndDeRef()
|
||||
void pointerCheckAndDeRef()
|
||||
{
|
||||
check("void foo(char *p) {\n"
|
||||
" if (!p) {\n"
|
||||
|
@ -662,6 +662,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("void foo(char *p) {\n"
|
||||
" if (p == NULL) {\n"
|
||||
" }\n"
|
||||
" printf(\"%c\", *p);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("void foo(abc *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" }\n"
|
||||
|
|
Loading…
Reference in New Issue