Null pointer: Added inconclusive error message when calling member function of NULL object.
This commit is contained in:
parent
3c509589b5
commit
d75ef01d2b
|
@ -850,6 +850,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
else if (CheckNullPointer::isPointerDeRef(tok2, unknown))
|
||||
nullPointerError(tok2, pointerName, linenr, inconclusive);
|
||||
|
||||
else if (unknown && _settings->inconclusive)
|
||||
nullPointerError(tok2, pointerName, linenr, true);
|
||||
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1370,6 +1370,19 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
{
|
||||
const char code[] = "void f(Fred *fred) {\n"
|
||||
" if (fred == NULL) { }\n"
|
||||
" fred->x();\n"
|
||||
"}";
|
||||
|
||||
check(code); // non-inconclusive
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check(code, true); // inconclusive
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check if fred is null at line 2\n", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Test CheckNullPointer::nullConstantDereference
|
||||
|
|
Loading…
Reference in New Issue