ErrorPath: better output

This commit is contained in:
Daniel Marjamäki 2017-05-19 17:29:16 +02:00
parent b53a2ff9eb
commit 55ae206ecc
5 changed files with 11 additions and 7 deletions

View File

@ -165,19 +165,19 @@ protected:
reportError(errmsg);
}
ErrorPath getErrorPath(const Token *errtok, const ValueFlow::Value *value) const {
ErrorPath getErrorPath(const Token *errtok, const ValueFlow::Value *value, const std::string &bug) const {
ErrorPath errorPath;
if (!value) {
errorPath.push_back(ErrorPathItem(errtok,""));
errorPath.push_back(ErrorPathItem(errtok,bug));
} else if (_settings->verbose || _settings->outputFormat == "clang") {
errorPath = value->errorPath;
errorPath.push_back(ErrorPathItem(errtok,""));
errorPath.push_back(ErrorPathItem(errtok,bug));
} else {
if (value->condition)
errorPath.push_back(ErrorPathItem(value->condition, "condition '" + value->condition->expressionString() + "'"));
//else if (!value->isKnown() || value->defaultArg)
// errorPath = value->callstack;
errorPath.push_back(ErrorPathItem(errtok,""));
errorPath.push_back(ErrorPathItem(errtok,bug));
}
return errorPath;
}

View File

@ -1780,7 +1780,7 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, MathLib::bigint in
void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::Value &index)
{
const ErrorPath errorPath = getErrorPath(tok, &index);
const ErrorPath errorPath = getErrorPath(tok, &index, "Negative array index");
std::ostringstream errmsg;
if (index.condition)
errmsg << ValueFlow::eitherTheConditionIsRedundant(index.condition)

View File

@ -473,7 +473,7 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
if (!_settings->isEnabled(value, inconclusive))
return;
const ErrorPath errorPath = getErrorPath(tok,value);
const ErrorPath errorPath = getErrorPath(tok, value, "Null pointer dereference");
if (value->condition) {
reportError(errorPath, Severity::warning, "nullPointerRedundantCheck", errmsgcond, CWE476, inconclusive || value->inconclusive);

View File

@ -1656,7 +1656,7 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
return;
}
const ErrorPath errorPath = getErrorPath(tok, value);
const ErrorPath errorPath = getErrorPath(tok, value, "Division by zero");
std::ostringstream errmsg;
if (value->condition)

View File

@ -425,6 +425,10 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
<< ": "
<< (verbose ? _verboseMessage : _shortMessage)
<< " [" << _id << ']';
if (_callStack.size() == 1U)
return text.str();
for (std::list<FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc)
text << std::endl
<< loc->getfile()