Fixed #2812 (false negative: null pointer dereference when returning struct member)

This commit is contained in:
Daniel Marjamäki 2011-07-25 21:40:32 +02:00
parent 63a0c6ad4a
commit 6e14da7eba
2 changed files with 16 additions and 5 deletions

View File

@ -985,6 +985,18 @@ private:
return ret->next();
}
else if (tok.str() == "return")
{
bool unknown = false;
const Token *vartok = tok.next();
if (vartok->str() == "*")
vartok = vartok->next();
if (vartok->varId() && CheckNullPointer::isPointerDeRef(vartok, unknown))
{
dereference(checks, vartok);
}
}
return &tok;
}

View File

@ -794,7 +794,6 @@ private:
" int x = &fred->x;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Ticket #2350
@ -908,14 +907,14 @@ private:
" my_type* p = 0;\n"
" return p->x;\n"
"}\n");
TODO_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("int foo()\n"
"{\n"
" struct my_type* p = 0;\n"
" return p->x;\n"
"}\n");
TODO_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("int foo()\n"
"{\n"
@ -923,7 +922,7 @@ private:
" p = 0; \n"
" return p->x;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
check("int foo()\n"
"{\n"
@ -931,7 +930,7 @@ private:
" p = 0; \n"
" return p->x;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
}
// Check if pointer is null and the dereference it