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