Emit better errorpath in CheckBufferOverrun::negativeIndexError

This commit is contained in:
Daniel Marjamäki 2017-05-16 19:08:47 +02:00
parent 970ff181de
commit f92e7b3bfc
2 changed files with 18 additions and 10 deletions

View File

@ -1780,11 +1780,14 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, MathLib::bigint in
void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::Value &index) void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::Value &index)
{ {
std::ostringstream ostr; const std::list<const Token *> errorPath = getErrorPath(tok, &index);
ostr << "Array index " << index.intvalue << " is out of bounds."; std::ostringstream errmsg;
if (index.condition) if (index.condition)
ostr << " Otherwise there is useless condition at line " << index.condition->linenr() << "."; errmsg << ValueFlow::eitherTheConditionIsRedundant(index.condition)
reportError(tok, index.condition ? Severity::warning : Severity::error, "negativeIndex", ostr.str(), CWE786, index.inconclusive); << ", otherwise there is negative array index " << index.intvalue << ".";
else
errmsg << "Array index " << index.intvalue << " is out of bounds.";
reportError(errorPath, index.condition ? Severity::warning : Severity::error, "negativeIndex", errmsg.str(), CWE786, index.inconclusive);
} }
CheckBufferOverrun::ArrayInfo::ArrayInfo() CheckBufferOverrun::ArrayInfo::ArrayInfo()

View File

@ -1658,12 +1658,17 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
const std::list<const Token *> errorPath = getErrorPath(tok, value); const std::list<const Token *> errorPath = getErrorPath(tok, value);
if (!value->condition) std::ostringstream errmsg;
reportError(errorPath, Severity::error, "zerodiv", "Division by zero.", CWE369, value->inconclusive); if (value->condition)
else { errmsg << ValueFlow::eitherTheConditionIsRedundant(value->condition)
const std::string linenr(MathLib::toString(tok->linenr())); << " or there is division by zero at line " << tok->linenr() << ".";
reportError(errorPath, Severity::warning, "zerodivcond", ValueFlow::eitherTheConditionIsRedundant(value->condition) + " or there is division by zero at line " + linenr + ".", CWE369, value->inconclusive); else
} errmsg << "Division by zero.";
reportError(errorPath,
value->condition ? Severity::warning : Severity::error,
value->condition ? "zerodivcond" : "zerodiv",
errmsg.str(), CWE369, value->inconclusive);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------