Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed many COPY_INSTEAD_OF_MOVE Coverity warnings #5944

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
mStdLogger = new StdLogger(settings);

CppCheck cppCheck(*mStdLogger, true, executeCommand);
cppCheck.settings() = settings;
cppCheck.settings() = settings; // this is a copy

const int ret = check_wrapper(cppCheck);

Expand Down
2 changes: 1 addition & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
{
std::list<ErrorMessage::FileLocation> locations;
locations.emplace_back(childname, 0, 0);
const ErrorMessage errmsg(locations,
const ErrorMessage errmsg(std::move(locations),
emptyString,
Severity::error,
"Internal error: " + msg,
Expand Down
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3255,7 +3255,7 @@ bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> sk
if (Token::Match(tok, "%cop%|[|.")) {
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1(), skipPredicate))
return false;
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), skipPredicate))
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), std::move(skipPredicate)))
return false;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
ErrorPath errorPath;
const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath);
if (var && isInScope(var->nameToken(), tok->scope())) {
errorDanglingReference(tok, var, errorPath);
errorDanglingReference(tok, var, std::move(errorPath));
continue;
}
// Reference to temporary
Expand Down
9 changes: 4 additions & 5 deletions lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
void errorUselessAssignmentPtrArg(const Token *tok);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
ErrorPath errorPath;
CheckAutoVariables c(nullptr,settings,errorLogger);
c.errorAutoVariableAssignment(nullptr, false);
c.errorReturnReference(nullptr, errorPath, false);
c.errorDanglingReference(nullptr, nullptr, errorPath);
c.errorReturnTempReference(nullptr, errorPath, false);
c.errorDanglingTempReference(nullptr, errorPath, false);
c.errorReturnReference(nullptr, ErrorPath{}, false);
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
c.errorInvalidDeallocation(nullptr, nullptr);
c.errorUselessAssignmentArg(nullptr);
c.errorUselessAssignmentPtrArg(nullptr);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ void CheckClass::checkThisUseAfterFree()

const Token * freeToken = nullptr;
std::set<const Function *> callstack;
checkThisUseAfterFreeRecursive(classScope, &func, &var, callstack, &freeToken);
checkThisUseAfterFreeRecursive(classScope, &func, &var, std::move(callstack), &freeToken);
}
}
}
Expand Down Expand Up @@ -3517,7 +3517,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
continue;

MyFileInfo::NameLoc nameLoc;
nameLoc.className = name;
nameLoc.className = std::move(name);
nameLoc.fileName = tokenizer->list.file(classScope->classDef);
nameLoc.lineNumber = classScope->classDef->linenr();
nameLoc.column = classScope->classDef->column();
Expand Down
11 changes: 6 additions & 5 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ void CheckCondition::duplicateCondition()
ErrorPath errorPath;
if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings, mTokenizer->isCPP()) &&
isSameExpression(mTokenizer->isCPP(), true, cond1, cond2, mSettings->library, true, true, &errorPath))
duplicateConditionError(cond1, cond2, errorPath);
duplicateConditionError(cond1, cond2, std::move(errorPath));
}
}

Expand Down Expand Up @@ -558,7 +558,7 @@ void CheckCondition::multiCondition()
else if (isOppositeCond(
true, mTokenizer->isCPP(), cond1, tok2->astOperand2(), mSettings->library, true, true, &errorPath) &&
!findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings, mTokenizer->isCPP()))
oppositeElseIfConditionError(cond1, tok2->astOperand2(), errorPath);
oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath));
}
}
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ void CheckCondition::checkIncorrectLogicOperator()
}

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

const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg;
const std::string& cond2VerboseMsg = expr1VerboseMsg;
Expand Down Expand Up @@ -1316,9 +1316,10 @@ void CheckCondition::checkIncorrectLogicOperator()
const std::string cond2str = conditionString(not2, expr2, op2, value2);
if (printWarning && (alwaysTrue || alwaysFalse)) {
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, errorPath);
incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, std::move(errorPath));
} else if (printStyle && (firstTrue || secondTrue)) {
const int which = isfloat ? sufficientCondition(op1, not1, d1, op2, not2, d2, isAnd) : sufficientCondition(op1, not1, i1, op2, not2, i2, isAnd);
// cppcheck-suppress accessMoved - TODO: FP - see #12174
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);
std::string text;
if (which != 0) {
text = "The condition '" + (which == 1 ? cond2str : cond1str) + "' is redundant since '" + (which == 1 ? cond1str : cond2str) + "' is sufficient.";
Expand Down
12 changes: 5 additions & 7 deletions lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,16 @@ class CPPCHECKLIB CheckCondition : public Check {
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckCondition c(nullptr, settings, errorLogger);

ErrorPath errorPath;

c.assignIfError(nullptr, nullptr, emptyString, false);
c.badBitmaskCheckError(nullptr);
c.comparisonError(nullptr, "&", 6, "==", 1, false);
c.duplicateConditionError(nullptr, nullptr, errorPath);
c.duplicateConditionError(nullptr, nullptr, ErrorPath{});
c.overlappingElseIfConditionError(nullptr, 1);
c.mismatchingBitAndError(nullptr, 0xf0, nullptr, 1);
c.oppositeInnerConditionError(nullptr, nullptr, errorPath);
c.identicalInnerConditionError(nullptr, nullptr, errorPath);
c.identicalConditionAfterEarlyExitError(nullptr, nullptr, errorPath);
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, errorPath);
c.oppositeInnerConditionError(nullptr, nullptr, ErrorPath{});
c.identicalInnerConditionError(nullptr, nullptr, ErrorPath{});
c.identicalConditionAfterEarlyExitError(nullptr, nullptr, ErrorPath{});
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, ErrorPath{});
c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.", false);
c.moduloAlwaysTrueFalseError(nullptr, "1");
c.clarifyConditionError(nullptr, true, false);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ void CheckOther::checkDuplicateBranch()
ErrorPath errorPath;
if (isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath))
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), errorPath);
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), std::move(errorPath));
}
}
}
Expand Down Expand Up @@ -2570,7 +2570,7 @@ void CheckOther::checkDuplicateExpression()
isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp))
duplicateValueTernaryError(tok);
else if (isSameExpression(cpp, true, tok->astOperand1(), tok->astOperand2(), mSettings->library, false, true, &errorPath))
duplicateExpressionTernaryError(tok, errorPath);
duplicateExpressionTernaryError(tok, std::move(errorPath));
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ class CPPCHECKLIB CheckOther : public Check {
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckOther c(nullptr, settings, errorLogger);

ErrorPath errorPath;

// error
c.zerodivError(nullptr, nullptr);
c.misusedScopeObjectError(nullptr, "varname");
Expand Down Expand Up @@ -326,12 +324,12 @@ class CPPCHECKLIB CheckOther : public Check {
c.selfAssignmentError(nullptr, "varname");
c.clarifyCalculationError(nullptr, "+");
c.clarifyStatementError(nullptr);
c.duplicateBranchError(nullptr, nullptr, errorPath);
c.duplicateBranchError(nullptr, nullptr, ErrorPath{});
c.duplicateAssignExpressionError(nullptr, nullptr, true);
c.oppositeExpressionError(nullptr, errorPath);
c.duplicateExpressionError(nullptr, nullptr, nullptr, errorPath);
c.oppositeExpressionError(nullptr, ErrorPath{});
c.duplicateExpressionError(nullptr, nullptr, nullptr, ErrorPath{});
c.duplicateValueTernaryError(nullptr);
c.duplicateExpressionTernaryError(nullptr, errorPath);
c.duplicateExpressionTernaryError(nullptr, ErrorPath{});
c.duplicateBreakError(nullptr, false);
c.unreachableCodeError(nullptr, nullptr, false);
c.unsignedLessThanZeroError(nullptr, nullptr, "varname");
Expand Down
10 changes: 5 additions & 5 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ void CheckStl::outOfBoundsError(const Token *tok, const std::string &containerNa
ErrorPath errorPath1 = getErrorPath(tok, containerSize, "Access out of bounds");
ErrorPath errorPath2 = getErrorPath(tok, indexValue, "Access out of bounds");
if (errorPath1.size() <= 1)
errorPath = errorPath2;
errorPath = std::move(errorPath2);
else if (errorPath2.size() <= 1)
errorPath = errorPath1;
else {
errorPath = errorPath1;
errorPath = std::move(errorPath1);
errorPath.splice(errorPath.end(), errorPath2);
}
}
Expand Down Expand Up @@ -993,7 +993,7 @@ namespace {
ep.emplace_front(ftok,
"After calling '" + ftok->expressionString() +
"', iterators or references to the container's data may be invalid .");
result.emplace_back(Info::Reference{tok, ep, ftok});
result.emplace_back(Info::Reference{tok, std::move(ep), ftok});
}
}
return result;
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void CheckStl::invalidContainer()
// Check the iterator is created before the change
if (val && val->tokvalue != tok && reaches(val->tokvalue, tok, library, &ep)) {
v = val;
errorPath = ep;
errorPath = std::move(ep);
return true;
}
return false;
Expand All @@ -1177,7 +1177,7 @@ void CheckStl::invalidContainer()
if (v) {
invalidContainerError(info.tok, r.tok, v, errorPath);
} else {
invalidContainerReferenceError(info.tok, r.tok, errorPath);
invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/checkstl.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,14 @@ class CPPCHECKLIB CheckStl : public Check {
void localMutexError(const Token *tok);

void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override {
ErrorPath errorPath;
CheckStl c(nullptr, settings, errorLogger);
c.outOfBoundsError(nullptr, "container", nullptr, "x", nullptr);
c.invalidIteratorError(nullptr, "iterator");
c.iteratorsError(nullptr, "container1", "container2");
c.iteratorsError(nullptr, nullptr, "container0", "container1");
c.iteratorsError(nullptr, nullptr, "container");
c.invalidContainerLoopError(nullptr, nullptr, errorPath);
c.invalidContainerError(nullptr, nullptr, nullptr, errorPath);
c.invalidContainerLoopError(nullptr, nullptr, ErrorPath{});
c.invalidContainerError(nullptr, nullptr, nullptr, ErrorPath{});
c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr);
c.mismatchingContainersError(nullptr, nullptr);
c.mismatchingContainerExpressionError(nullptr, nullptr);
Expand Down
3 changes: 1 addition & 2 deletions lib/checkuninitvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ class CPPCHECKLIB CheckUninitVar : public Check {
void uninitdataError(const Token *tok, const std::string &varname);
void uninitvarError(const Token *tok, const std::string &varname, ErrorPath errorPath);
void uninitvarError(const Token *tok, const std::string &varname) {
ErrorPath errorPath;
uninitvarError(tok, varname, errorPath);
uninitvarError(tok, varname, ErrorPath{});
}
void uninitvarError(const Token *tok, const std::string &varname, Alloc alloc) {
if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
locationList.back().fileIndex = fileIndex;
}

const ErrorMessage errmsg(locationList, emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
if (errorLogger)
errorLogger->reportErr(errmsg);
else
Expand Down
8 changes: 4 additions & 4 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
--addrIndex;
const std::string addr = mExtTokens[addrIndex];
std::string name = unquote(getSpelling());
Token *reftok = addtoken(tokenList, name.empty() ? "<NoName>" : name);
Token *reftok = addtoken(tokenList, name.empty() ? "<NoName>" : std::move(name));
mData->ref(addr, reftok);
return reftok;
}
Expand Down Expand Up @@ -1085,10 +1085,10 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
Token *par2 = addtoken(tokenList, ")");
par1->link(par2);
par2->link(par1);
createScope(tokenList, Scope::ScopeType::eIf, thenCode, iftok);
createScope(tokenList, Scope::ScopeType::eIf, std::move(thenCode), iftok);
if (elseCode) {
elseCode->addtoken(tokenList, "else");
createScope(tokenList, Scope::ScopeType::eElse, elseCode, tokenList.back());
createScope(tokenList, Scope::ScopeType::eElse, std::move(elseCode), tokenList.back());
}
return nullptr;
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
Token *par2 = addtoken(tokenList, ")");
par1->link(par2);
par2->link(par1);
createScope(tokenList, Scope::ScopeType::eWhile, body, whiletok);
createScope(tokenList, Scope::ScopeType::eWhile, std::move(body), whiletok);
return nullptr;
}
return addtoken(tokenList, "?" + nodeType + "?");
Expand Down
12 changes: 6 additions & 6 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
if (pos != std::string::npos)
details.resize(pos + 1);
}
throw InternalError(nullptr, message, details);
throw InternalError(nullptr, std::move(message), std::move(details));
}

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

ErrorMessage errmsg(callstack,
ErrorMessage errmsg(std::move(callstack),
"",
Severity::error,
output.msg,
Expand Down Expand Up @@ -1041,7 +1041,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
const ErrorMessage::FileLocation loc1(filename, 0, 0);
std::list<ErrorMessage::FileLocation> callstack(1, loc1);

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


ErrorMessage errmsg(loclist,
ErrorMessage errmsg(std::move(loclist),
emptyString,
Severity::information,
msg.str(),
Expand All @@ -1573,7 +1573,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
loclist.emplace_back(file);
}

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

errmsg.file0 = fixedpath;
errmsg.file0 = std::move(fixedpath);
errmsg.setmsg(messageString);
reportErr(errmsg);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void ErrorMessage::deserialize(const std::string &data)
}
}

results[elem++] = temp;
results[elem++] = std::move(temp);
}

if (!iss.good())
Expand Down
4 changes: 2 additions & 2 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command)
// we can only set it globally but in this context it needs to be treated per file
}
}
fsSetDefines(fs, defs);
fsSetDefines(fs, std::move(defs));
}

bool ImportProject::importCompileCommands(std::istream &istr)
Expand Down Expand Up @@ -630,7 +630,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::
const std::string::size_type pos = path.find("$(IncludePath)");
if (pos != std::string::npos)
path.replace(pos, 14U, includePath);
includePath = path;
includePath = std::move(path);
}
}
}
Expand Down
Loading
Loading