Null pointer: prefer longer error message that says 'otherwise condition at line X is redundant'
This commit is contained in:
parent
4a7b60942b
commit
7426bd3daf
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue