Emit better errorpath in CheckBufferOverrun::negativeIndexError
This commit is contained in:
parent
970ff181de
commit
f92e7b3bfc
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue