Fixed #2159 (False positive: Null pointer dereference 'if (!x) return *y;')
This commit is contained in:
parent
3fb17baa12
commit
94fc13f0c4
|
@ -461,7 +461,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
|
||||
if (Token::Match(tok2, "goto|return|continue|break|throw|if"))
|
||||
{
|
||||
if (Token::Match(tok2, "return * %var%"))
|
||||
if (Token::Match(tok2, "return * %varid%", varid))
|
||||
nullPointerError(tok2, tok->strAt(3));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ private:
|
|||
TEST_CASE(nullpointer7);
|
||||
TEST_CASE(nullpointer8);
|
||||
TEST_CASE(nullpointer9);
|
||||
TEST_CASE(nullpointer10); // check if pointer is null and then dereference it
|
||||
TEST_CASE(checkAndDeRef); // check if pointer is null and then dereference it
|
||||
}
|
||||
|
||||
void check(const char code[])
|
||||
|
@ -631,7 +631,7 @@ private:
|
|||
}
|
||||
|
||||
// Check if pointer is null and the dereference it
|
||||
void nullpointer10()
|
||||
void checkAndDeRef()
|
||||
{
|
||||
check("void foo(char *p) {\n"
|
||||
" if (!p) {\n"
|
||||
|
@ -671,6 +671,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(bool p) {\n"
|
||||
" if (!p) {\n"
|
||||
" }\n"
|
||||
" return *x;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// This is why this check can't be used on the simplified token list
|
||||
check("void f(Foo *foo) {\n"
|
||||
" if (!dynamic_cast<bar *>(foo)) {\n"
|
||||
|
|
Loading…
Reference in New Issue