From cd53d10970d0835c53b130e92e524bebafe211d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 16 May 2017 23:12:35 +0200 Subject: [PATCH] ErrorPath: More information about assignments --- lib/errorlogger.h | 8 ++++++-- lib/valueflow.cpp | 25 +++++++++++++++++++++++-- lib/valueflow.h | 4 +--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 6c352ddc1..29d3c7f28 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -221,8 +221,12 @@ public: unsigned int line; unsigned int fileNumber; - std::string getinfo() const { return _info; } - void setinfo(const std::string &i) { _info = i; } + std::string getinfo() const { + return _info; + } + void setinfo(const std::string &i) { + _info = i; + } private: std::string _file; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 5ec5ea8ec..ac33e579e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1971,8 +1971,12 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat continue; std::list values = tok->astOperand2()->values(); - for (std::list::iterator it = values.begin(); it != values.end(); ++it) - it->errorPath.push_back(ErrorPathItem(tok->astOperand2(),"assignment")); + for (std::list::iterator it = values.begin(); it != values.end(); ++it) { + std::string info = "Assignment"; + if (it->isIntValue()) + info += ", integer value " + MathLib::toString(it->intvalue); + it->errorPath.push_back(ErrorPathItem(tok->astOperand2(), info)); + } const bool constValue = tok->astOperand2()->isNumber(); if (tokenlist->isCPP() && Token::Match(var->typeStartToken(), "bool|_Bool")) { @@ -2926,6 +2930,23 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab } } +ValueFlow::Value::Value(const Token *c, long long val) + : valueType(INT), + intvalue(val), + tokvalue(nullptr), + floatValue(0.0), + moveKind(NonMovedVariable), + varvalue(val), + condition(c), + varId(0U), + conditional(false), + inconclusive(false), + defaultArg(false), + valueKind(ValueKind::Possible) +{ + errorPath.push_back(ErrorPathItem(c, "Condition '" + c->expressionString() + "'")); +} + const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr, const Settings *settings) { if (expr && expr->values().empty()) { diff --git a/lib/valueflow.h b/lib/valueflow.h index e249e06a6..147c36008 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -38,9 +38,7 @@ namespace ValueFlow { typedef std::list ErrorPath; explicit Value(long long val = 0) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(0), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) {} - Value(const Token *c, long long val) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(c), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) { - errorPath.push_back(ErrorPathItem(c, "condition")); - } + Value(const Token *c, long long val); bool operator==(const Value &rhs) const { if (valueType != rhs.valueType)