Skip to content

Commit a2ecf17

Browse files
authored
fixed many COPY_INSTEAD_OF_MOVE Coverity warnings (#5944)
1 parent 6802050 commit a2ecf17

28 files changed

Lines changed: 96 additions & 102 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() = settings; // this is a copy
198198

199199
const int ret = check_wrapper(cppCheck);
200200

cli/processexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
392392
{
393393
std::list<ErrorMessage::FileLocation> locations;
394394
locations.emplace_back(childname, 0, 0);
395-
const ErrorMessage errmsg(locations,
395+
const ErrorMessage errmsg(std::move(locations),
396396
emptyString,
397397
Severity::error,
398398
"Internal error: " + msg,

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
9191
void errorUselessAssignmentPtrArg(const Token *tok);
9292

9393
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
94-
ErrorPath errorPath;
9594
CheckAutoVariables c(nullptr,settings,errorLogger);
9695
c.errorAutoVariableAssignment(nullptr, false);
97-
c.errorReturnReference(nullptr, errorPath, false);
98-
c.errorDanglingReference(nullptr, nullptr, errorPath);
99-
c.errorReturnTempReference(nullptr, errorPath, false);
100-
c.errorDanglingTempReference(nullptr, errorPath, false);
96+
c.errorReturnReference(nullptr, ErrorPath{}, false);
97+
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
98+
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
99+
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
101100
c.errorInvalidDeallocation(nullptr, nullptr);
102101
c.errorUselessAssignmentArg(nullptr);
103102
c.errorUselessAssignmentPtrArg(nullptr);

lib/checkclass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,7 +3343,7 @@ void CheckClass::checkThisUseAfterFree()
33433343

33443344
const Token * freeToken = nullptr;
33453345
std::set<const Function *> callstack;
3346-
checkThisUseAfterFreeRecursive(classScope, &func, &var, callstack, &freeToken);
3346+
checkThisUseAfterFreeRecursive(classScope, &func, &var, std::move(callstack), &freeToken);
33473347
}
33483348
}
33493349
}
@@ -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: 6 additions & 5 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

@@ -558,7 +558,7 @@ void CheckCondition::multiCondition()
558558
else if (isOppositeCond(
559559
true, mTokenizer->isCPP(), cond1, tok2->astOperand2(), mSettings->library, true, true, &errorPath) &&
560560
!findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings, mTokenizer->isCPP()))
561-
oppositeElseIfConditionError(cond1, tok2->astOperand2(), errorPath);
561+
oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath));
562562
}
563563
}
564564
}
@@ -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,10 @@ 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+
// cppcheck-suppress accessMoved - TODO: FP - see #12174
1322+
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);
13221323
std::string text;
13231324
if (which != 0) {
13241325
text = "The condition '" + (which == 1 ? cond2str : cond1str) + "' is redundant since '" + (which == 1 ? cond1str : cond2str) + "' is sufficient.";

lib/checkcondition.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,16 @@ class CPPCHECKLIB CheckCondition : public Check {
175175
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
176176
CheckCondition c(nullptr, settings, errorLogger);
177177

178-
ErrorPath errorPath;
179-
180178
c.assignIfError(nullptr, nullptr, emptyString, false);
181179
c.badBitmaskCheckError(nullptr);
182180
c.comparisonError(nullptr, "&", 6, "==", 1, false);
183-
c.duplicateConditionError(nullptr, nullptr, errorPath);
181+
c.duplicateConditionError(nullptr, nullptr, ErrorPath{});
184182
c.overlappingElseIfConditionError(nullptr, 1);
185183
c.mismatchingBitAndError(nullptr, 0xf0, nullptr, 1);
186-
c.oppositeInnerConditionError(nullptr, nullptr, errorPath);
187-
c.identicalInnerConditionError(nullptr, nullptr, errorPath);
188-
c.identicalConditionAfterEarlyExitError(nullptr, nullptr, errorPath);
189-
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, errorPath);
184+
c.oppositeInnerConditionError(nullptr, nullptr, ErrorPath{});
185+
c.identicalInnerConditionError(nullptr, nullptr, ErrorPath{});
186+
c.identicalConditionAfterEarlyExitError(nullptr, nullptr, ErrorPath{});
187+
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, ErrorPath{});
190188
c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.", false);
191189
c.moduloAlwaysTrueFalseError(nullptr, "1");
192190
c.clarifyConditionError(nullptr, true, false);

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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ class CPPCHECKLIB CheckOther : public Check {
293293
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
294294
CheckOther c(nullptr, settings, errorLogger);
295295

296-
ErrorPath errorPath;
297-
298296
// error
299297
c.zerodivError(nullptr, nullptr);
300298
c.misusedScopeObjectError(nullptr, "varname");
@@ -326,12 +324,12 @@ class CPPCHECKLIB CheckOther : public Check {
326324
c.selfAssignmentError(nullptr, "varname");
327325
c.clarifyCalculationError(nullptr, "+");
328326
c.clarifyStatementError(nullptr);
329-
c.duplicateBranchError(nullptr, nullptr, errorPath);
327+
c.duplicateBranchError(nullptr, nullptr, ErrorPath{});
330328
c.duplicateAssignExpressionError(nullptr, nullptr, true);
331-
c.oppositeExpressionError(nullptr, errorPath);
332-
c.duplicateExpressionError(nullptr, nullptr, nullptr, errorPath);
329+
c.oppositeExpressionError(nullptr, ErrorPath{});
330+
c.duplicateExpressionError(nullptr, nullptr, nullptr, ErrorPath{});
333331
c.duplicateValueTernaryError(nullptr);
334-
c.duplicateExpressionTernaryError(nullptr, errorPath);
332+
c.duplicateExpressionTernaryError(nullptr, ErrorPath{});
335333
c.duplicateBreakError(nullptr, false);
336334
c.unreachableCodeError(nullptr, nullptr, false);
337335
c.unsignedLessThanZeroError(nullptr, nullptr, "varname");

0 commit comments

Comments
 (0)