Null pointer: Added inconclusive error message when calling member function of NULL object.

This commit is contained in:
Daniel Marjamäki 2011-10-29 15:48:54 +02:00
parent 3c509589b5
commit d75ef01d2b
2 changed files with 16 additions and 0 deletions

View File

@ -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;
}

View File

@ -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