Fixed #2166 (false positive: possible null pointer dereference)
This commit is contained in:
parent
bc8ecf2aa7
commit
c29940b114
|
@ -402,7 +402,11 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||||
if (tok1->varId() == varid)
|
if (tok1->varId() == varid)
|
||||||
{
|
{
|
||||||
bool unknown = false;
|
bool unknown = false;
|
||||||
if (CheckNullPointer::isPointerDeRef(tok1, unknown))
|
if (Token::Match(tok1->tokAt(-2), "%varid% = %varid% .", varid))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (CheckNullPointer::isPointerDeRef(tok1, unknown))
|
||||||
{
|
{
|
||||||
nullPointerError(tok1, varname, tok->linenr());
|
nullPointerError(tok1, varname, tok->linenr());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -36,8 +36,8 @@ private:
|
||||||
{
|
{
|
||||||
TEST_CASE(nullpointer1);
|
TEST_CASE(nullpointer1);
|
||||||
TEST_CASE(nullpointer2);
|
TEST_CASE(nullpointer2);
|
||||||
TEST_CASE(nullpointer3); // dereferencing struct and then checking if it's null
|
TEST_CASE(structDerefAndCheck); // dereferencing struct and then checking if it's null
|
||||||
TEST_CASE(nullpointer4);
|
TEST_CASE(pointerDerefAndCheck);
|
||||||
TEST_CASE(nullpointer5); // References should not be checked
|
TEST_CASE(nullpointer5); // References should not be checked
|
||||||
TEST_CASE(nullpointer6);
|
TEST_CASE(nullpointer6);
|
||||||
TEST_CASE(nullpointer7);
|
TEST_CASE(nullpointer7);
|
||||||
|
@ -171,7 +171,7 @@ private:
|
||||||
// Dereferencing a struct and then checking if it is null
|
// Dereferencing a struct and then checking if it is null
|
||||||
// This is checked by this function:
|
// This is checked by this function:
|
||||||
// CheckOther::nullPointerStructByDeRefAndChec
|
// CheckOther::nullPointerStructByDeRefAndChec
|
||||||
void nullpointer3()
|
void structDerefAndCheck()
|
||||||
{
|
{
|
||||||
// errors..
|
// errors..
|
||||||
check("void foo(struct ABC *abc)\n"
|
check("void foo(struct ABC *abc)\n"
|
||||||
|
@ -289,7 +289,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dereferencing a pointer and then checking if it is null
|
// Dereferencing a pointer and then checking if it is null
|
||||||
void nullpointer4()
|
void pointerDerefAndCheck()
|
||||||
{
|
{
|
||||||
// errors..
|
// errors..
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
|
@ -370,6 +370,14 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(x *p)\n"
|
||||||
|
"{\n"
|
||||||
|
" p = p->next;\n"
|
||||||
|
" if (!p)\n"
|
||||||
|
" ;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nullpointer5()
|
void nullpointer5()
|
||||||
|
|
Loading…
Reference in New Issue