Skip to content

Commit fcc0493

Browse files
authored
fixed some Variable copied when it could be moved Coverity warnings (danmar#7505)
1 parent c79862b commit fcc0493

File tree

10 files changed

+14
-16
lines changed

10 files changed

+14
-16
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,7 @@ void CheckClass::checkMemset()
14331433
type = typeTok->type()->classScope;
14341434

14351435
if (type) {
1436-
const std::set<const Scope *> parsedTypes;
1437-
checkMemsetType(scope, tok, type, false, parsedTypes);
1436+
checkMemsetType(scope, tok, type, false, {});
14381437
}
14391438
} else if (tok->variable() && tok->variable()->isPointer() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) {
14401439
const Library::AllocFunc* alloc = mSettings->library.getAllocFuncInfo(tok->tokAt(2));

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ void CheckCondition::checkIncorrectLogicOperator()
12611261
if (!isfloat && isOppositeCond(isLogicalOr, tok->astOperand1(), tok->astOperand2(), *mSettings, true, true, &errorPath)) {
12621262
if (!isIfConstexpr(tok)) {
12631263
const bool alwaysTrue(isLogicalOr);
1264-
incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, errorPath);
1264+
incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, std::move(errorPath));
12651265
}
12661266
continue;
12671267
}

lib/checknullpointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo &ctu, const std::
693693
fi->file0,
694694
warning ? Severity::warning : Severity::error,
695695
message,
696-
id,
696+
std::move(id),
697697
CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
698698
errorLogger.reportErr(errmsg);
699699

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,13 @@ void CheckOther::redundantBitwiseOperationInSwitchError()
760760
// case 4: b = b | 1;
761761
else if (Token::Match(tok2->previous(), ";|{|}|: %var% = %name% %or%|& %num% ;") &&
762762
tok2->varId() == tok2->tokAt(2)->varId()) {
763-
const std::string bitOp = tok2->strAt(3) + tok2->strAt(4);
763+
std::string bitOp = tok2->strAt(3) + tok2->strAt(4);
764764
const auto i2 = utils::as_const(varsWithBitsSet).find(tok2->varId());
765765

766766
// This variable has not had a bit operation performed on it yet, so just make a note of it
767767
if (i2 == varsWithBitsSet.end()) {
768768
varsWithBitsSet[tok2->varId()] = tok2;
769-
bitOperations[tok2->varId()] = bitOp;
769+
bitOperations[tok2->varId()] = std::move(bitOp);
770770
}
771771

772772
// The same bit operation has been performed on the same variable twice, so report an error

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command)
306306
defs += defval;
307307
defs += ';';
308308
} else if (F=='U')
309-
fs.undefs.insert(fval);
309+
fs.undefs.insert(std::move(fval));
310310
else if (F=='I') {
311311
std::string i = std::move(fval);
312312
if (i.size() > 1 && i[0] == '\"' && i.back() == '\"')

lib/library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
221221
cfgfolders.emplace_back(FILESDIR "/cfg");
222222
#endif
223223
if (exename) {
224-
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(Path::getCurrentExecutablePath(exename))));
224+
std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(Path::getCurrentExecutablePath(exename))));
225225
cfgfolders.push_back(exepath + "cfg");
226-
cfgfolders.push_back(exepath);
226+
cfgfolders.push_back(std::move(exepath));
227227
}
228228

229229
while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) {

lib/suppressions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ std::string SuppressionList::parseFile(std::istream &istr)
9898
if (pos < line.size() - 1 && line[pos] == '/' && line[pos + 1] == '/')
9999
continue;
100100

101-
const std::string errmsg(addSuppressionLine(line));
101+
std::string errmsg(addSuppressionLine(line));
102102
if (!errmsg.empty())
103103
return errmsg;
104104
}

lib/templatesimplifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,9 +3246,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
32463246

32473247
// New classname/funcname..
32483248
const std::string newName(templateDeclaration.name() + " < " + typeForNewName + " >");
3249-
const std::string newFullName(templateDeclaration.scope() + (templateDeclaration.scope().empty() ? "" : " :: ") + newName);
3249+
std::string newFullName(templateDeclaration.scope() + (templateDeclaration.scope().empty() ? "" : " :: ") + newName);
32503250

3251-
if (expandedtemplates.insert(newFullName).second) {
3251+
if (expandedtemplates.insert(std::move(newFullName)).second) {
32523252
expandTemplate(templateDeclaration, instantiation, typeParametersInDeclaration, newName, !specialized && !isVar);
32533253
instantiated = true;
32543254
mChanged = true;

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6805,7 +6805,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
68056805
value.valueType = ValueFlow::Value::ValueType::TOK;
68066806
value.tokvalue = tok;
68076807
value.setKnown();
6808-
values.push_back(value);
6808+
values.push_back(std::move(value));
68096809
} else if (Token::simpleMatch(tok, "(")) {
68106810
const Token* constructorArgs = tok;
68116811
values = getContainerSizeFromConstructor(constructorArgs, tok->valueType(), settings, true);

lib/vf_settokenvalue.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ namespace ValueFlow
303303
Token* next = nullptr;
304304
const Library::Container::Yield yields = getContainerYield(parent, settings, next);
305305
if (yields == Library::Container::Yield::SIZE) {
306-
Value v(value);
307-
v.valueType = Value::ValueType::INT;
308-
setTokenValue(next, std::move(v), settings);
306+
value.valueType = Value::ValueType::INT;
307+
setTokenValue(next, std::move(value), settings);
309308
} else if (yields == Library::Container::Yield::EMPTY) {
310309
Value v(value);
311310
v.valueType = Value::ValueType::INT;

0 commit comments

Comments
 (0)