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)
{
std::ostringstream ostr;
ostr << "Array index " << index.intvalue << " is out of bounds.";
const std::list<const Token *> errorPath = getErrorPath(tok, &index);
std::ostringstream errmsg;
if (index.condition)
ostr << " Otherwise there is useless condition at line " << index.condition->linenr() << ".";
reportError(tok, index.condition ? Severity::warning : Severity::error, "negativeIndex", ostr.str(), CWE786, index.inconclusive);
errmsg << ValueFlow::eitherTheConditionIsRedundant(index.condition)
<< ", 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()

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);
if (!value->condition)
reportError(errorPath, Severity::error, "zerodiv", "Division by zero.", CWE369, value->inconclusive);
else {
const std::string linenr(MathLib::toString(tok->linenr()));
reportError(errorPath, Severity::warning, "zerodivcond", ValueFlow::eitherTheConditionIsRedundant(value->condition) + " or there is division by zero at line " + linenr + ".", CWE369, value->inconclusive);
}
std::ostringstream errmsg;
if (value->condition)
errmsg << ValueFlow::eitherTheConditionIsRedundant(value->condition)
<< " or there is division by zero at line " << tok->linenr() << ".";
else
errmsg << "Division by zero.";
reportError(errorPath,
value->condition ? Severity::warning : Severity::error,
value->condition ? "zerodivcond" : "zerodiv",
errmsg.str(), CWE369, value->inconclusive);
}
//---------------------------------------------------------------------------