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)
|
if (varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Is variable a pointer?
|
||||||
|
if (!isPointer(varid))
|
||||||
|
continue;
|
||||||
|
|
||||||
// Get variable name for the loop variable
|
// Get variable name for the loop variable
|
||||||
const std::string varname(tok->strAt(2));
|
const std::string varname(tok->strAt(2));
|
||||||
|
|
||||||
|
@ -229,9 +233,7 @@ void CheckNullPointer::nullPointerAfterLoop()
|
||||||
// Is the loop variable dereferenced?
|
// Is the loop variable dereferenced?
|
||||||
if (CheckNullPointer::isPointerDeRef(tok2, unknown))
|
if (CheckNullPointer::isPointerDeRef(tok2, unknown))
|
||||||
{
|
{
|
||||||
// Is loop variable a pointer?
|
nullPointerError(tok2, varname, tok->linenr());
|
||||||
if (isPointer(varid))
|
|
||||||
nullPointerError(tok2, varname);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ private:
|
||||||
" while (tok);\n"
|
" while (tok);\n"
|
||||||
" tok = tok->next();\n"
|
" tok = tok->next();\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue