Null pointer: prefer longer error message that says 'otherwise condition at line X is redundant'

This commit is contained in:
Daniel Marjamäki 2011-03-28 18:44:25 +02:00
parent 4a7b60942b
commit 7426bd3daf
2 changed files with 6 additions and 4 deletions

View File

@ -207,6 +207,10 @@ void CheckNullPointer::nullPointerAfterLoop()
if (varid == 0)
continue;
// Is variable a pointer?
if (!isPointer(varid))
continue;
// Get variable name for the loop variable
const std::string varname(tok->strAt(2));
@ -229,9 +233,7 @@ void CheckNullPointer::nullPointerAfterLoop()
// Is the loop variable dereferenced?
if (CheckNullPointer::isPointerDeRef(tok2, unknown))
{
// Is loop variable a pointer?
if (isPointer(varid))
nullPointerError(tok2, varname);
nullPointerError(tok2, varname, tok->linenr());
}
break;
}

View File

@ -78,7 +78,7 @@ private:
" while (tok);\n"
" tok = tok->next();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: tok\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check if tok is null at line 3\n", errout.str());
check("void foo()\n"
"{\n"