Skip to content

Commit fff2e49

Browse files
committed
fixed many COPY_INSTEAD_OF_MOVE Coverity warnings
1 parent faaabb1 commit fff2e49

26 files changed

+74
-74
lines changed

cli/cppcheckexecutor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
194194
mStdLogger = new StdLogger(settings);
195195

196196
CppCheck cppCheck(*mStdLogger, true, executeCommand);
197-
cppCheck.settings() = settings;
197+
cppCheck.settings() = std::move(settings);
198198

199199
const int ret = check_wrapper(cppCheck);
200200

lib/astutils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@ int getArgumentPos(const Variable* var, const Function* f)
30703070
});
30713071
if (arg_it == f->argumentList.end())
30723072
return -1;
3073-
return std::distance(f->argumentList.cbegin(), arg_it);
3073+
return std::distance(f->argumentList.cbegin(), std::move(arg_it));
30743074
}
30753075

30763076
const Token* getIteratorExpression(const Token* tok)
@@ -3255,7 +3255,7 @@ bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> sk
32553255
if (Token::Match(tok, "%cop%|[|.")) {
32563256
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1(), skipPredicate))
32573257
return false;
3258-
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), skipPredicate))
3258+
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), std::move(skipPredicate)))
32593259
return false;
32603260
return true;
32613261
}

lib/checkautovariables.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
575575
ErrorPath errorPath;
576576
const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath);
577577
if (var && isInScope(var->nameToken(), tok->scope())) {
578-
errorDanglingReference(tok, var, errorPath);
578+
errorDanglingReference(tok, var, std::move(errorPath));
579579
continue;
580580
}
581581
// Reference to temporary

lib/checkautovariables.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
9797
c.errorReturnReference(nullptr, errorPath, false);
9898
c.errorDanglingReference(nullptr, nullptr, errorPath);
9999
c.errorReturnTempReference(nullptr, errorPath, false);
100-
c.errorDanglingTempReference(nullptr, errorPath, false);
100+
c.errorDanglingTempReference(nullptr, std::move(errorPath), false);
101101
c.errorInvalidDeallocation(nullptr, nullptr);
102102
c.errorUselessAssignmentArg(nullptr);
103103
c.errorUselessAssignmentPtrArg(nullptr);

lib/checkclass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
35173517
continue;
35183518

35193519
MyFileInfo::NameLoc nameLoc;
3520-
nameLoc.className = name;
3520+
nameLoc.className = std::move(name);
35213521
nameLoc.fileName = tokenizer->list.file(classScope->classDef);
35223522
nameLoc.lineNumber = classScope->classDef->linenr();
35233523
nameLoc.column = classScope->classDef->column();

lib/checkcondition.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void CheckCondition::duplicateCondition()
505505
ErrorPath errorPath;
506506
if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings, mTokenizer->isCPP()) &&
507507
isSameExpression(mTokenizer->isCPP(), true, cond1, cond2, mSettings->library, true, true, &errorPath))
508-
duplicateConditionError(cond1, cond2, errorPath);
508+
duplicateConditionError(cond1, cond2, std::move(errorPath));
509509
}
510510
}
511511

@@ -1193,7 +1193,7 @@ void CheckCondition::checkIncorrectLogicOperator()
11931193
}
11941194

11951195
const std::string cond1 = expr1 + " " + tok->str() + " (" + expr2 + " " + tok->astOperand2()->str() + " " + expr3 + ")";
1196-
const std::string cond2 = expr1;
1196+
const std::string cond2 = std::move(expr1);
11971197

11981198
const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg;
11991199
const std::string& cond2VerboseMsg = expr1VerboseMsg;
@@ -1316,9 +1316,9 @@ void CheckCondition::checkIncorrectLogicOperator()
13161316
const std::string cond2str = conditionString(not2, expr2, op2, value2);
13171317
if (printWarning && (alwaysTrue || alwaysFalse)) {
13181318
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
1319-
incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, errorPath);
1319+
incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, std::move(errorPath));
13201320
} else if (printStyle && (firstTrue || secondTrue)) {
1321-
const int which = isfloat ? sufficientCondition(op1, not1, d1, op2, not2, d2, isAnd) : sufficientCondition(op1, not1, i1, op2, not2, i2, isAnd);
1321+
const int which = isfloat ? sufficientCondition(std::move(op1), not1, d1, std::move(op2), not2, d2, isAnd) : sufficientCondition(std::move(op1), not1, i1, std::move(op2), not2, i2, isAnd);
13221322
std::string text;
13231323
if (which != 0) {
13241324
text = "The condition '" + (which == 1 ? cond2str : cond1str) + "' is redundant since '" + (which == 1 ? cond1str : cond2str) + "' is sufficient.";

lib/checkother.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ void CheckOther::checkDuplicateBranch()
22482248
ErrorPath errorPath;
22492249
if (isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
22502250
isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath))
2251-
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), errorPath);
2251+
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), std::move(errorPath));
22522252
}
22532253
}
22542254
}
@@ -2570,7 +2570,7 @@ void CheckOther::checkDuplicateExpression()
25702570
isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp))
25712571
duplicateValueTernaryError(tok);
25722572
else if (isSameExpression(cpp, true, tok->astOperand1(), tok->astOperand2(), mSettings->library, false, true, &errorPath))
2573-
duplicateExpressionTernaryError(tok, errorPath);
2573+
duplicateExpressionTernaryError(tok, std::move(errorPath));
25742574
}
25752575
}
25762576
}

lib/checkother.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class CPPCHECKLIB CheckOther : public Check {
331331
c.oppositeExpressionError(nullptr, errorPath);
332332
c.duplicateExpressionError(nullptr, nullptr, nullptr, errorPath);
333333
c.duplicateValueTernaryError(nullptr);
334-
c.duplicateExpressionTernaryError(nullptr, errorPath);
334+
c.duplicateExpressionTernaryError(nullptr, std::move(errorPath));
335335
c.duplicateBreakError(nullptr, false);
336336
c.unreachableCodeError(nullptr, nullptr, false);
337337
c.unsignedLessThanZeroError(nullptr, nullptr, "varname");

lib/checkstl.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void CheckStl::outOfBoundsError(const Token *tok, const std::string &containerNa
260260
ErrorPath errorPath1 = getErrorPath(tok, containerSize, "Access out of bounds");
261261
ErrorPath errorPath2 = getErrorPath(tok, indexValue, "Access out of bounds");
262262
if (errorPath1.size() <= 1)
263-
errorPath = errorPath2;
263+
errorPath = std::move(errorPath2);
264264
else if (errorPath2.size() <= 1)
265265
errorPath = errorPath1;
266266
else {
@@ -993,7 +993,7 @@ namespace {
993993
ep.emplace_front(ftok,
994994
"After calling '" + ftok->expressionString() +
995995
"', iterators or references to the container's data may be invalid .");
996-
result.emplace_back(Info::Reference{tok, ep, ftok});
996+
result.emplace_back(Info::Reference{tok, std::move(ep), ftok});
997997
}
998998
}
999999
return result;
@@ -1165,7 +1165,7 @@ void CheckStl::invalidContainer()
11651165
// Check the iterator is created before the change
11661166
if (val && val->tokvalue != tok && reaches(val->tokvalue, tok, library, &ep)) {
11671167
v = val;
1168-
errorPath = ep;
1168+
errorPath = std::move(ep);
11691169
return true;
11701170
}
11711171
return false;
@@ -1177,7 +1177,7 @@ void CheckStl::invalidContainer()
11771177
if (v) {
11781178
invalidContainerError(info.tok, r.tok, v, errorPath);
11791179
} else {
1180-
invalidContainerReferenceError(info.tok, r.tok, errorPath);
1180+
invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath));
11811181
}
11821182
}
11831183
}

lib/checkstl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class CPPCHECKLIB CheckStl : public Check {
251251
c.iteratorsError(nullptr, nullptr, "container0", "container1");
252252
c.iteratorsError(nullptr, nullptr, "container");
253253
c.invalidContainerLoopError(nullptr, nullptr, errorPath);
254-
c.invalidContainerError(nullptr, nullptr, nullptr, errorPath);
254+
c.invalidContainerError(nullptr, nullptr, nullptr, std::move(errorPath));
255255
c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr);
256256
c.mismatchingContainersError(nullptr, nullptr);
257257
c.mismatchingContainerExpressionError(nullptr, nullptr);

lib/checkuninitvar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CPPCHECKLIB CheckUninitVar : public Check {
118118
void uninitvarError(const Token *tok, const std::string &varname, ErrorPath errorPath);
119119
void uninitvarError(const Token *tok, const std::string &varname) {
120120
ErrorPath errorPath;
121-
uninitvarError(tok, varname, errorPath);
121+
uninitvarError(tok, varname, std::move(errorPath));
122122
}
123123
void uninitvarError(const Token *tok, const std::string &varname, Alloc alloc) {
124124
if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL)

lib/checkunusedfunctions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
363363
locationList.back().fileIndex = fileIndex;
364364
}
365365

366-
const ErrorMessage errmsg(locationList, emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
366+
const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
367367
if (errorLogger)
368368
errorLogger->reportErr(errmsg);
369369
else

lib/clangimport.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ namespace clangimport {
305305
if (it != mNotFound.end()) {
306306
for (Token *reftok: it->second)
307307
ref(addr, reftok);
308-
mNotFound.erase(it);
308+
mNotFound.erase(std::move(it));
309309
}
310310
}
311311

@@ -947,7 +947,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
947947
--addrIndex;
948948
const std::string addr = mExtTokens[addrIndex];
949949
std::string name = unquote(getSpelling());
950-
Token *reftok = addtoken(tokenList, name.empty() ? "<NoName>" : name);
950+
Token *reftok = addtoken(tokenList, name.empty() ? "<NoName>" : std::move(name));
951951
mData->ref(addr, reftok);
952952
return reftok;
953953
}
@@ -1088,7 +1088,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
10881088
createScope(tokenList, Scope::ScopeType::eIf, thenCode, iftok);
10891089
if (elseCode) {
10901090
elseCode->addtoken(tokenList, "else");
1091-
createScope(tokenList, Scope::ScopeType::eElse, elseCode, tokenList.back());
1091+
createScope(tokenList, Scope::ScopeType::eElse, std::move(elseCode), tokenList.back());
10921092
}
10931093
return nullptr;
10941094
}
@@ -1255,7 +1255,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
12551255
Token *par2 = addtoken(tokenList, ")");
12561256
par1->link(par2);
12571257
par2->link(par1);
1258-
createScope(tokenList, Scope::ScopeType::eWhile, body, whiletok);
1258+
createScope(tokenList, Scope::ScopeType::eWhile, std::move(body), whiletok);
12591259
return nullptr;
12601260
}
12611261
return addtoken(tokenList, "?" + nodeType + "?");

lib/cppcheck.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
287287
if (pos != std::string::npos)
288288
details.resize(pos + 1);
289289
}
290-
throw InternalError(nullptr, message, details);
290+
throw InternalError(nullptr, std::move(message), std::move(details));
291291
}
292292

293293
std::vector<picojson::value> addonResult;
@@ -664,7 +664,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
664664
const ErrorMessage::FileLocation loc1(file, output.location.line, output.location.col);
665665
std::list<ErrorMessage::FileLocation> callstack(1, loc1);
666666

667-
ErrorMessage errmsg(callstack,
667+
ErrorMessage errmsg(std::move(callstack),
668668
"",
669669
Severity::error,
670670
output.msg,
@@ -1041,7 +1041,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
10411041
const ErrorMessage::FileLocation loc1(filename, 0, 0);
10421042
std::list<ErrorMessage::FileLocation> callstack(1, loc1);
10431043

1044-
ErrorMessage errmsg(callstack,
1044+
ErrorMessage errmsg(std::move(callstack),
10451045
emptyString,
10461046
Severity::error,
10471047
fullmsg,
@@ -1551,7 +1551,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo
15511551
msg << " For more details, use --enable=information.";
15521552

15531553

1554-
ErrorMessage errmsg(loclist,
1554+
ErrorMessage errmsg(std::move(loclist),
15551555
emptyString,
15561556
Severity::information,
15571557
msg.str(),
@@ -1573,7 +1573,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
15731573
loclist.emplace_back(file);
15741574
}
15751575

1576-
ErrorMessage errmsg(loclist,
1576+
ErrorMessage errmsg(std::move(loclist),
15771577
emptyString,
15781578
Severity::information,
15791579
"The configuration '" + configuration + "' was not checked because its code equals another one.",
@@ -1756,7 +1756,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
17561756
else
17571757
errmsg.severity = Severity::style;
17581758

1759-
errmsg.file0 = fixedpath;
1759+
errmsg.file0 = std::move(fixedpath);
17601760
errmsg.setmsg(messageString);
17611761
reportErr(errmsg);
17621762
}

lib/errorlogger.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void ErrorMessage::deserialize(const std::string &data)
337337
}
338338
}
339339

340-
results[elem++] = temp;
340+
results[elem++] = std::move(temp);
341341
}
342342

343343
if (!iss.good())

lib/importproject.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command)
337337
// we can only set it globally but in this context it needs to be treated per file
338338
}
339339
}
340-
fsSetDefines(fs, defs);
340+
fsSetDefines(fs, std::move(defs));
341341
}
342342

343343
bool ImportProject::importCompileCommands(std::istream &istr)
@@ -630,7 +630,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::
630630
const std::string::size_type pos = path.find("$(IncludePath)");
631631
if (pos != std::string::npos)
632632
path.replace(pos, 14U, includePath);
633-
includePath = path;
633+
includePath = std::move(path);
634634
}
635635
}
636636
}

lib/library.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
637637
return Error(ErrorCode::DUPLICATE_PLATFORM_TYPE, type_name);
638638
return Error(ErrorCode::PLATFORM_TYPE_REDEFINED, type_name);
639639
}
640-
mPlatformTypes[type_name] = type;
640+
mPlatformTypes[type_name] = std::move(type);
641641
} else {
642642
for (const std::string &p : platform) {
643643
const PlatformType * const type_ptr = platform_type(type_name, p);
@@ -890,7 +890,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
890890
wi.message = message;
891891
}
892892

893-
functionwarn[name] = wi;
893+
functionwarn[name] = std::move(wi);
894894
} else if (functionnodename == "container") {
895895
const char* const action_ptr = functionnode->Attribute("action");
896896
Container::Action action = Container::Action::NO_ACTION;

lib/pathanalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ PathAnalysis::Progress PathAnalysis::forwardRecursive(const Token* tok, Info inf
7676
info.tok = tok;
7777
if (f(info) == Progress::Break)
7878
return Progress::Break;
79-
if (tok->astOperand2() && forwardRecursive(tok->astOperand2(), info, f) == Progress::Break)
79+
if (tok->astOperand2() && forwardRecursive(tok->astOperand2(), std::move(info), f) == Progress::Break)
8080
return Progress::Break;
8181
return Progress::Continue;
8282
}

lib/preprocessor.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
552552
}
553553

554554
configs_if.push_back((cmdtok->str() == "ifndef") ? std::string() : config);
555-
configs_ifndef.push_back((cmdtok->str() == "ifndef") ? config : std::string());
555+
configs_ifndef.push_back((cmdtok->str() == "ifndef") ? std::move(config) : std::string());
556556
ret.insert(cfg(configs_if,userDefines));
557557
} else if (cmdtok->str() == "elif" || cmdtok->str() == "else") {
558558
if (getConfigsElseIsFalse(configs_if,userDefines)) {
@@ -831,7 +831,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens
831831
std::list<simplecpp::IfCond> ifCond;
832832
simplecpp::TokenList tokens2(files);
833833
simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, &macroUsage, &ifCond);
834-
mMacroUsage = macroUsage;
834+
mMacroUsage = std::move(macroUsage);
835835
mIfCond = ifCond;
836836

837837
handleErrors(outputList, throwError);
@@ -910,7 +910,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
910910
ErrorMessage::FileLocation loc(file, linenr, 0);
911911
locationList.push_back(std::move(loc));
912912
}
913-
mErrorLogger->reportErr(ErrorMessage(locationList,
913+
mErrorLogger->reportErr(ErrorMessage(std::move(locationList),
914914
mFile0,
915915
Severity::error,
916916
msg,

lib/programmemory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static bool evalSameCondition(const ProgramMemory& state,
12271227
programMemoryParseCondition(pm, storedValue, nullptr, settings, true);
12281228
if (pm == state)
12291229
return false;
1230-
return conditionIsTrue(cond, pm, settings);
1230+
return conditionIsTrue(cond, std::move(pm), settings);
12311231
}
12321232

12331233
static void pruneConditions(std::vector<const Token*>& conds,

lib/suppressions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ bool Suppressions::reportUnmatchedSuppressions(const std::list<Suppressions::Sup
557557
std::list<::ErrorMessage::FileLocation> callStack;
558558
if (!s.fileName.empty())
559559
callStack.emplace_back(s.fileName, s.lineNumber, 0);
560-
errorLogger.reportErr(::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
560+
errorLogger.reportErr(::ErrorMessage(std::move(callStack), emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
561561
err = true;
562562
}
563563
return err;

lib/symboldatabase.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
549549
// out of line function
550550
if (const Token *endTok = Tokenizer::isFunctionHead(end, ";")) {
551551
tok = endTok;
552-
scope->addFunction(function);
552+
scope->addFunction(std::move(function));
553553
}
554554

555555
// inline function
@@ -3028,7 +3028,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
30283028
}
30293029
}
30303030

3031-
param = short_path;
3031+
param = std::move(short_path);
30323032
if (Token::simpleMatch(second->next(), param.c_str(), param.size())) {
30333033
second = second->tokAt(int(short_path_length));
30343034
arg_path_length = 0;

0 commit comments

Comments
 (0)