ErrorPath: better output
This commit is contained in:
parent
b53a2ff9eb
commit
55ae206ecc
|
@ -165,19 +165,19 @@ protected:
|
||||||
reportError(errmsg);
|
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;
|
ErrorPath errorPath;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
errorPath.push_back(ErrorPathItem(errtok,""));
|
errorPath.push_back(ErrorPathItem(errtok,bug));
|
||||||
} else if (_settings->verbose || _settings->outputFormat == "clang") {
|
} else if (_settings->verbose || _settings->outputFormat == "clang") {
|
||||||
errorPath = value->errorPath;
|
errorPath = value->errorPath;
|
||||||
errorPath.push_back(ErrorPathItem(errtok,""));
|
errorPath.push_back(ErrorPathItem(errtok,bug));
|
||||||
} else {
|
} else {
|
||||||
if (value->condition)
|
if (value->condition)
|
||||||
errorPath.push_back(ErrorPathItem(value->condition, "condition '" + value->condition->expressionString() + "'"));
|
errorPath.push_back(ErrorPathItem(value->condition, "condition '" + value->condition->expressionString() + "'"));
|
||||||
//else if (!value->isKnown() || value->defaultArg)
|
//else if (!value->isKnown() || value->defaultArg)
|
||||||
// errorPath = value->callstack;
|
// errorPath = value->callstack;
|
||||||
errorPath.push_back(ErrorPathItem(errtok,""));
|
errorPath.push_back(ErrorPathItem(errtok,bug));
|
||||||
}
|
}
|
||||||
return errorPath;
|
return errorPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1780,7 +1780,7 @@ 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)
|
||||||
{
|
{
|
||||||
const ErrorPath errorPath = getErrorPath(tok, &index);
|
const ErrorPath errorPath = getErrorPath(tok, &index, "Negative array index");
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
if (index.condition)
|
if (index.condition)
|
||||||
errmsg << ValueFlow::eitherTheConditionIsRedundant(index.condition)
|
errmsg << ValueFlow::eitherTheConditionIsRedundant(index.condition)
|
||||||
|
|
|
@ -473,7 +473,7 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
|
||||||
if (!_settings->isEnabled(value, inconclusive))
|
if (!_settings->isEnabled(value, inconclusive))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const ErrorPath errorPath = getErrorPath(tok,value);
|
const ErrorPath errorPath = getErrorPath(tok, value, "Null pointer dereference");
|
||||||
|
|
||||||
if (value->condition) {
|
if (value->condition) {
|
||||||
reportError(errorPath, Severity::warning, "nullPointerRedundantCheck", errmsgcond, CWE476, inconclusive || value->inconclusive);
|
reportError(errorPath, Severity::warning, "nullPointerRedundantCheck", errmsgcond, CWE476, inconclusive || value->inconclusive);
|
||||||
|
|
|
@ -1656,7 +1656,7 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrorPath errorPath = getErrorPath(tok, value);
|
const ErrorPath errorPath = getErrorPath(tok, value, "Division by zero");
|
||||||
|
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
if (value->condition)
|
if (value->condition)
|
||||||
|
|
|
@ -425,6 +425,10 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
||||||
<< ": "
|
<< ": "
|
||||||
<< (verbose ? _verboseMessage : _shortMessage)
|
<< (verbose ? _verboseMessage : _shortMessage)
|
||||||
<< " [" << _id << ']';
|
<< " [" << _id << ']';
|
||||||
|
|
||||||
|
if (_callStack.size() == 1U)
|
||||||
|
return text.str();
|
||||||
|
|
||||||
for (std::list<FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc)
|
for (std::list<FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc)
|
||||||
text << std::endl
|
text << std::endl
|
||||||
<< loc->getfile()
|
<< loc->getfile()
|
||||||
|
|
Loading…
Reference in New Issue