Skip to content

Commit 949bfe2

Browse files
committed
fixed many COPY_INSTEAD_OF_MOVE Coverity warnings
1 parent ee4c6b1 commit 949bfe2

26 files changed

Lines changed: 76 additions & 76 deletions

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ int getArgumentPos(const Variable* var, const Function* f)
30683068
});
30693069
if (arg_it == f->argumentList.end())
30703070
return -1;
3071-
return std::distance(f->argumentList.cbegin(), arg_it);
3071+
return std::distance(f->argumentList.cbegin(), std::move(arg_it));
30723072
}
30733073

30743074
const Token* getIteratorExpression(const Token* tok)
@@ -3253,7 +3253,7 @@ bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> sk
32533253
if (Token::Match(tok, "%cop%|[|.")) {
32543254
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1(), skipPredicate))
32553255
return false;
3256-
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), skipPredicate))
3256+
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), std::move(skipPredicate)))
32573257
return false;
32583258
return true;
32593259
}

lib/checkautovariables.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class CPPCHECKLIB CheckStl : public Check {
246246
c.iteratorsError(nullptr, nullptr, "container0", "container1");
247247
c.iteratorsError(nullptr, nullptr, "container");
248248
c.invalidContainerLoopError(nullptr, nullptr, errorPath);
249-
c.invalidContainerError(nullptr, nullptr, nullptr, errorPath);
249+
c.invalidContainerError(nullptr, nullptr, nullptr, std::move(errorPath));
250250
c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr);
251251
c.mismatchingContainersError(nullptr, nullptr);
252252
c.mismatchingContainerExpressionError(nullptr, nullptr);

0 commit comments

Comments
 (0)