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 more COPY_INSTEAD_OF_MOVE Coverity warnings #5949

Merged
merged 1 commit into from
Feb 7, 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 lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3605,7 +3605,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<C
locationList.emplace_back(nameLoc.fileName, nameLoc.lineNumber, nameLoc.column);
locationList.emplace_back(it->second.fileName, it->second.lineNumber, it->second.column);

const ErrorMessage errmsg(locationList,
const ErrorMessage errmsg(std::move(locationList),
emptyString,
Severity::error,
"$symbol:" + nameLoc.className +
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ void CheckOther::checkDuplicateExpression()
continue;
}
}
duplicateExpressionError(tok->astOperand1(), tok->astOperand2(), tok, errorPath);
duplicateExpressionError(tok->astOperand1(), tok->astOperand2(), tok, std::move(errorPath));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ErrorMessage::FileLocation> callstack(1, loc1);

ErrorMessage errmsg(callstack,
ErrorMessage errmsg(std::move(callstack),
filename,
Severity::error,
o.msg,
Expand Down
2 changes: 1 addition & 1 deletion lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MathLib::bigint> values{LLONG_MIN, LLONG_MAX};
mUnknownReturnValues[name] = values;
mUnknownReturnValues[name] = std::move(values);
}
}
} else if (functionnodename == "arg") {
Expand Down
4 changes: 2 additions & 2 deletions lib/pathanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ void PathAnalysis::forward(const std::function<Progress(const Info&)>& 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)
Expand Down
2 changes: 1 addition & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens
simplecpp::TokenList tokens2(files);
simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, &macroUsage, &ifCond);
mMacroUsage = std::move(macroUsage);
mIfCond = ifCond;
mIfCond = std::move(ifCond);

handleErrors(outputList, throwError);

Expand Down
2 changes: 1 addition & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8033,7 +8033,9 @@ std::string ValueType::str() const
ret += " &";
else if (reference == Reference::RValue)
ret += " &&";
return ret.empty() ? ret : ret.substr(1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables in ternaries are not moved on return so I split the statement instead of introducing an explicit move.

if (ret.empty())
return ret;
return ret.substr(1);
}

void ValueType::setDebugPath(const Token* tok, SourceLocation ctx, SourceLocation local)
Expand Down
22 changes: 11 additions & 11 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ static void setTokenValue(Token* tok,
return;
const std::list<ValueFlow::Value> &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?
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -3956,7 +3956,7 @@ static void valueFlowForwardLifetime(Token * tok, TokenList &tokenlist, ErrorLog
if (Token::Match(tok->previous(), "%var% {|(") && isVariableDecl(tok->previous())) {
std::list<ValueFlow::Value> 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();
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -6527,7 +6527,7 @@ struct ConditionHandler {
const std::string& op(parent->str());
std::list<ValueFlow::Value> values;
if (op == "&&")
values = andValues;
values = std::move(andValues);
else if (op == "||")
values = std::move(orValues);
if (allowKnown && (Token::Match(condTok, "==|!=") || cond.isBool()))
Expand Down Expand Up @@ -8467,7 +8467,7 @@ static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger * errorLogge
if (!inTok)
continue;
const std::list<ValueFlow::Value>& 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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -9240,7 +9240,7 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s
valueFlowForward(const_cast<Token*>(functionScope->bodyStart->next()),
functionScope->bodyEnd,
arg.nameToken(),
argValues,
std::move(argValues),
tokenlist,
errorLogger,
settings);
Expand Down
Loading