diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 31d7bae75..b6ea1589d 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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 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() diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 46e65070c..8ed5cb916 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1658,12 +1658,17 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value) const std::list 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); } //---------------------------------------------------------------------------