From 4a5ac68272c054b4b3403cd1f750ff4297a7bb1e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 6 Feb 2024 14:33:07 +0100 Subject: [PATCH] fixed more `COPY_INSTEAD_OF_MOVE` Coverity warnings --- lib/checkclass.cpp | 2 +- lib/checkother.cpp | 2 +- lib/checkstl.cpp | 6 +++--- lib/cppcheck.cpp | 2 +- lib/importproject.cpp | 2 +- lib/library.cpp | 2 +- lib/pathanalysis.cpp | 4 ++-- lib/preprocessor.cpp | 2 +- lib/programmemory.cpp | 2 +- lib/symboldatabase.cpp | 4 +++- lib/valueflow.cpp | 22 +++++++++++----------- 11 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 5bed9fb51c8..4ba5c964951 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3605,7 +3605,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::listsecond.fileName, it->second.lineNumber, it->second.column); - const ErrorMessage errmsg(locationList, + const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::error, "$symbol:" + nameLoc.className + diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d3f5723ff84..779841cdf8a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2510,7 +2510,7 @@ void CheckOther::checkDuplicateExpression() continue; } } - duplicateExpressionError(tok->astOperand1(), tok->astOperand2(), tok, errorPath); + duplicateExpressionError(tok->astOperand1(), tok->astOperand2(), tok, std::move(errorPath)); } } } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 0a1d4eba5a1..a9b12f61a0a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -262,7 +262,7 @@ void CheckStl::outOfBoundsError(const Token *tok, const std::string &containerNa if (errorPath1.size() <= 1) errorPath = std::move(errorPath2); else if (errorPath2.size() <= 1) - errorPath = errorPath1; + errorPath = std::move(errorPath1); else { errorPath = std::move(errorPath1); errorPath.splice(errorPath.end(), errorPath2); @@ -1155,7 +1155,7 @@ void CheckStl::invalidContainer() if (var->isArgument() || (!var->isReference() && !var->isRValueReference() && !isVariableDecl(tok) && reaches(var->nameToken(), tok, library, &ep))) { - errorPath = ep; + errorPath = std::move(ep); return true; } } @@ -1175,7 +1175,7 @@ void CheckStl::invalidContainer() errorPath.insert(errorPath.end(), info.errorPath.cbegin(), info.errorPath.cend()); errorPath.insert(errorPath.end(), r.errorPath.cbegin(), r.errorPath.cend()); if (v) { - invalidContainerError(info.tok, r.tok, v, errorPath); + invalidContainerError(info.tok, r.tok, v, std::move(errorPath)); } else { invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath)); } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index cf0c99df3da..cc8829c0a33 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -957,7 +957,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string const ErrorMessage::FileLocation loc1(file, o.location.line, o.location.col); std::list callstack(1, loc1); - ErrorMessage errmsg(callstack, + ErrorMessage errmsg(std::move(callstack), filename, Severity::error, o.msg, diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 57e0fdff127..ea3878ebe07 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -358,7 +358,7 @@ bool ImportProject::importCompileCommands(std::istream &istr) if (!endsWith(dirpath, '/')) dirpath += '/'; - const std::string directory = dirpath; + const std::string directory = std::move(dirpath); std::string command; if (obj.count("arguments")) { diff --git a/lib/library.cpp b/lib/library.cpp index 50775b31b9c..b89dcff958b 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -721,7 +721,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co if (const char *unknownReturnValues = functionnode->Attribute("unknownValues")) { if (std::strcmp(unknownReturnValues, "all") == 0) { std::vector values{LLONG_MIN, LLONG_MAX}; - mUnknownReturnValues[name] = values; + mUnknownReturnValues[name] = std::move(values); } } } else if (functionnodename == "arg") { diff --git a/lib/pathanalysis.cpp b/lib/pathanalysis.cpp index 045c0f50803..ceecb16e4c5 100644 --- a/lib/pathanalysis.cpp +++ b/lib/pathanalysis.cpp @@ -150,7 +150,7 @@ PathAnalysis::Progress PathAnalysis::forwardRange(const Token* startToken, const if (Token::simpleMatch(endBlock, "} else {")) { if (checkElse) { i.errorPath.back().second = "Assuming condition is false."; - const Progress result = forwardRange(endCond->next(), endBlock, i, f); + const Progress result = forwardRange(endCond->next(), endBlock, std::move(i), f); if (result == Progress::Break) return Progress::Break; } @@ -179,7 +179,7 @@ void PathAnalysis::forward(const std::function& f) const return; const Token * endToken = endScope->bodyEnd; Info info{start, ErrorPath{}, true}; - forwardRange(start, endToken, info, f); + forwardRange(start, endToken, std::move(info), f); } bool reaches(const Token * start, const Token * dest, const Library& library, ErrorPath* errorPath) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 93175118612..ea7d2513e34 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -832,7 +832,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens simplecpp::TokenList tokens2(files); simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, ¯oUsage, &ifCond); mMacroUsage = std::move(macroUsage); - mIfCond = ifCond; + mIfCond = std::move(ifCond); handleErrors(outputList, throwError); diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 1b160bc1c3d..6b082514f14 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -490,7 +490,7 @@ void ProgramMemoryState::assume(const Token* tok, bool b, bool isEmpty) origin = origin->link(); } } - replace(pm, origin); + replace(std::move(pm), origin); } void ProgramMemoryState::removeModifiedVars(const Token* tok) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 098154ff8e4..ae2bc481ed9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -8033,7 +8033,9 @@ std::string ValueType::str() const ret += " &"; else if (reference == Reference::RValue) ret += " &&"; - return ret.empty() ? ret : ret.substr(1); + if (ret.empty()) + return ret; + return ret.substr(1); } void ValueType::setDebugPath(const Token* tok, SourceLocation ctx, SourceLocation local) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index cda431b17d9..e181bf3cc89 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -787,7 +787,7 @@ static void setTokenValue(Token* tok, return; const std::list &values = op->values(); if (std::find(values.cbegin(), values.cend(), value) != values.cend()) - setTokenValue(parent, value, settings); + setTokenValue(parent, std::move(value), settings); } } else if (!value.isImpossible()) { // is condition only depending on 1 variable? @@ -948,7 +948,7 @@ static void setTokenValue(Token* tok, if (Token::simpleMatch(parent, "-") && value2.bound == result.bound && value2.bound != ValueFlow::Value::Bound::Point) result.invertBound(); - setTokenValue(parent, result, settings); + setTokenValue(parent, std::move(result), settings); } } } @@ -1634,7 +1634,7 @@ static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings const ValueFlow::Value& v = arg->values().front(); result.intvalue = v.intvalue; result.errorPath.insert(result.errorPath.end(), v.errorPath.cbegin(), v.errorPath.cend()); - setTokenValue(tok, result, settings); + setTokenValue(tok, std::move(result), settings); } } } @@ -3956,7 +3956,7 @@ static void valueFlowForwardLifetime(Token * tok, TokenList &tokenlist, ErrorLog if (Token::Match(tok->previous(), "%var% {|(") && isVariableDecl(tok->previous())) { std::list values = tok->values(); values.remove_if(&isNotLifetimeValue); - valueFlowForward(nextAfterAstRightmostLeaf(tok), ValueFlow::getEndOfExprScope(tok), tok->previous(), values, tokenlist, errorLogger, settings); + valueFlowForward(nextAfterAstRightmostLeaf(tok), ValueFlow::getEndOfExprScope(tok), tok->previous(), std::move(values), tokenlist, errorLogger, settings); return; } Token *parent = tok->astParent(); @@ -5059,7 +5059,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co if (Token::simpleMatch(parent, "(")) setTokenValue(parent, std::move(value), settings); else - setTokenValue(parent->tokAt(2), value, settings); + setTokenValue(parent->tokAt(2), std::move(value), settings); if (!rt.token->variable()) { LifetimeStore ls = LifetimeStore{ @@ -5087,7 +5087,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co value.lifetimeScope = ValueFlow::Value::LifetimeScope::Local; value.lifetimeKind = ValueFlow::Value::LifetimeKind::SubObject; value.tokvalue = tok; - value.errorPath = errorPath; + value.errorPath = std::move(errorPath); setTokenValue(ptok, std::move(value), settings); valueFlowForwardLifetime(ptok, tokenlist, errorLogger, settings); } @@ -6527,7 +6527,7 @@ struct ConditionHandler { const std::string& op(parent->str()); std::list values; if (op == "&&") - values = andValues; + values = std::move(andValues); else if (op == "||") values = std::move(orValues); if (allowKnown && (Token::Match(condTok, "==|!=") || cond.isBool())) @@ -8467,7 +8467,7 @@ static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger * errorLogge if (!inTok) continue; const std::list& values = inTok->values(); - valueFlowForwardAssign(inTok, tok, vars, values, false, tokenlist, errorLogger, settings); + valueFlowForwardAssign(inTok, tok, std::move(vars), values, false, tokenlist, errorLogger, settings); } } else if (Token::simpleMatch(tok->astParent(), ". release ( )")) { const Token* parent = ftok->astParent(); @@ -8749,7 +8749,7 @@ static void valueFlowContainerSetTokValue(TokenList& tokenlist, ErrorLogger* con value.setKnown(); Token* start = initList->link() ? initList->link() : initList->next(); if (tok->variable() && tok->variable()->isConst()) { - valueFlowForwardConst(start, tok->variable()->scope()->bodyEnd, tok->variable(), {value}, settings); + valueFlowForwardConst(start, tok->variable()->scope()->bodyEnd, tok->variable(), {std::move(value)}, settings); } else { valueFlowForward(start, tok, std::move(value), tokenlist, errorLogger, settings); } @@ -8910,7 +8910,7 @@ static void valueFlowContainerSize(TokenList& tokenlist, ValueFlow::Value value(tok->tokAt(2)->astOperand2()->values().front()); value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; value.setKnown(); - valueFlowForward(tok->linkAt(2), containerTok, value, tokenlist, errorLogger, settings); + valueFlowForward(tok->linkAt(2), containerTok, std::move(value), tokenlist, errorLogger, settings); } else if (action == Library::Container::Action::PUSH && !isIteratorPair(getArguments(tok->tokAt(2)))) { ValueFlow::Value value(0); value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; @@ -9240,7 +9240,7 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s valueFlowForward(const_cast(functionScope->bodyStart->next()), functionScope->bodyEnd, arg.nameToken(), - argValues, + std::move(argValues), tokenlist, errorLogger, settings);