Fixed #599 (False positive: null pointer dereference)
This commit is contained in:
parent
88251f5ac0
commit
439ff8b144
|
@ -1159,7 +1159,7 @@ void CheckOther::nullPointer()
|
|||
|
||||
else if (Token::Match(tok2, "if ( !| %varid% )", varid1))
|
||||
{
|
||||
nullPointerError(tok1, varname);
|
||||
nullPointerError(tok1, varname, tok2->linenr());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1344,6 +1344,13 @@ void CheckOther::nullPointerError(const Token *tok, const std::string &varname)
|
|||
reportError(tok, Severity::error, "nullPointer", "Possible null pointer dereference: " + varname);
|
||||
}
|
||||
|
||||
void CheckOther::nullPointerError(const Token *tok, const std::string &varname, const int line)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << line;
|
||||
reportError(tok, Severity::error, "nullPointer", "Possible null pointer dereference: " + varname + " - otherwise it is redundant to check if " + varname + " is null at line " + ostr.str());
|
||||
}
|
||||
|
||||
void CheckOther::zerodivError(const Token *tok)
|
||||
{
|
||||
reportError(tok, Severity::error, "zerodiv", "Division by zero");
|
||||
|
|
|
@ -143,6 +143,7 @@ public:
|
|||
void conditionAlwaysTrueFalse(const Token *tok, const std::string &truefalse);
|
||||
void strPlusChar(const Token *tok);
|
||||
void nullPointerError(const Token *tok, const std::string &varname);
|
||||
void nullPointerError(const Token *tok, const std::string &varname, const int line);
|
||||
void zerodivError(const Token *tok);
|
||||
void postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement);
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ private:
|
|||
" if (!abc)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: abc\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 4\n", errout.str());
|
||||
|
||||
// ok dereferencing in a condition
|
||||
checkNullPointer("void foo(struct ABC *abc)\n"
|
||||
|
|
Loading…
Reference in New Issue