Add errorpath for accessMoved message

This commit is contained in:
Daniel Marjamäki 2017-10-10 15:49:15 +02:00
parent d22614bdaa
commit fbccb3ae55
3 changed files with 20 additions and 9 deletions

View File

@ -2658,7 +2658,7 @@ void CheckOther::checkAccessOfMovedVariable()
} }
} }
if (accessOfMoved || (inconclusive && reportInconclusive)) if (accessOfMoved || (inconclusive && reportInconclusive))
accessMovedError(tok, tok->str(), movedValue->moveKind, inconclusive || movedValue->isInconclusive()); accessMovedError(tok, tok->str(), movedValue, inconclusive || movedValue->isInconclusive());
} }
} }
} }
@ -2676,11 +2676,17 @@ bool CheckOther::isMovedParameterAllowedForInconclusiveFunction(const Token * to
return true; return true;
} }
void CheckOther::accessMovedError(const Token *tok, const std::string &varname, ValueFlow::Value::MoveKind moveKind, bool inconclusive) void CheckOther::accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive)
{ {
if (!tok) {
reportError(tok, Severity::warning, "accessMoved", "Access of moved variable v.", CWE672, false);
reportError(tok, Severity::warning, "accessForwarded", "Access of forwarded variable v.", CWE672, false);
return;
}
const char * errorId = nullptr; const char * errorId = nullptr;
const char * kindString = nullptr; std::string kindString;
switch (moveKind) { switch (value->moveKind) {
case ValueFlow::Value::MovedVariable: case ValueFlow::Value::MovedVariable:
errorId = "accessMoved"; errorId = "accessMoved";
kindString = "moved"; kindString = "moved";
@ -2692,8 +2698,9 @@ void CheckOther::accessMovedError(const Token *tok, const std::string &varname,
default: default:
return; return;
} }
const std::string errmsg(std::string("Access of ") + kindString + " variable " + varname + "."); const std::string errmsg("Access of " + kindString + " variable " + varname + ".");
reportError(tok, Severity::warning, errorId, errmsg, CWE672, inconclusive); const ErrorPath errorPath = getErrorPath(tok, value, errmsg);
reportError(errorPath, Severity::warning, errorId, errmsg, CWE672, inconclusive);
} }

View File

@ -257,7 +257,7 @@ private:
void unusedLabelError(const Token* tok, bool inSwitch); void unusedLabelError(const Token* tok, bool inSwitch);
void unknownEvaluationOrder(const Token* tok); void unknownEvaluationOrder(const Token* tok);
static bool isMovedParameterAllowedForInconclusiveFunction(const Token * tok); static bool isMovedParameterAllowedForInconclusiveFunction(const Token * tok);
void accessMovedError(const Token *tok, const std::string &varname, ValueFlow::Value::MoveKind moveKind, bool inconclusive); void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive);
void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition); void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition);
void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions); void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
@ -313,8 +313,7 @@ private:
c.unusedLabelError(nullptr, true); c.unusedLabelError(nullptr, true);
c.unusedLabelError(nullptr, false); c.unusedLabelError(nullptr, false);
c.unknownEvaluationOrder(nullptr); c.unknownEvaluationOrder(nullptr);
c.accessMovedError(nullptr, "v", ValueFlow::Value::MovedVariable, false); c.accessMovedError(nullptr, "v", nullptr, false);
c.accessMovedError(nullptr, "v", ValueFlow::Value::ForwardedVariable, false);
c.funcArgNamesDifferent("function", 1, nullptr, nullptr); c.funcArgNamesDifferent("function", 1, nullptr, nullptr);
std::vector<const Token *> nullvec; std::vector<const Token *> nullvec;

View File

@ -2122,6 +2122,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
ValueFlow::Value value; ValueFlow::Value value;
value.valueType = ValueFlow::Value::MOVED; value.valueType = ValueFlow::Value::MOVED;
value.moveKind = ValueFlow::Value::NonMovedVariable; value.moveKind = ValueFlow::Value::NonMovedVariable;
value.errorPath.push_back(ErrorPathItem(tok, "Calling " + tok->next()->expressionString() + " makes " + tok->str() + " 'non-moved'"));
value.setKnown(); value.setKnown();
std::list<ValueFlow::Value> values; std::list<ValueFlow::Value> values;
values.push_back(value); values.push_back(value);
@ -2158,6 +2159,10 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
ValueFlow::Value value; ValueFlow::Value value;
value.valueType = ValueFlow::Value::MOVED; value.valueType = ValueFlow::Value::MOVED;
value.moveKind = moveKind; value.moveKind = moveKind;
if (moveKind == ValueFlow::Value::MovedVariable)
value.errorPath.push_back(ErrorPathItem(tok, "Calling std::move(" + varTok->str() + ")"));
else // if (moveKind == ValueFlow::Value::ForwardedVariable)
value.errorPath.push_back(ErrorPathItem(tok, "Calling std::forward(" + varTok->str() + ")"));
value.setKnown(); value.setKnown();
std::list<ValueFlow::Value> values; std::list<ValueFlow::Value> values;
values.push_back(value); values.push_back(value);