Skip to content

Commit ba468e9

Browse files
committed
lib: use std::move() where appropriate
Suggested by Coverity: ``` Error: COPY_INSTEAD_OF_MOVE: src/lib/filter.cc:114:25: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/filter.cc:114:25: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/filter.cc:205:29: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::set<DefEvent, std::less<DefEvent>, std::allocator<DefEvent> >::insert(std::set<DefEvent, std::less<DefEvent>, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/filter.cc:205:29: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-cov.cc:428:28: copy_constructor_call: "str" is copied and then passed-by-reference as parameter to STL insertion function "std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::insert(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::value_type const &)", when it could be moved instead. src/lib/parser-cov.cc:428:28: remediation: Use "std::move(""str"")" instead of "str". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-gcc.cc:552:46: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/parser-gcc.cc:552:46: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-gcc.cc:558:46: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/parser-gcc.cc:558:46: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-json-sarif.cc:205:13: copy_assignment_call: "uri" is copied in call to copy assignment for class "std::string const", when it could be moved instead. src/lib/parser-json-sarif.cc:205:30: remediation: Use "std::move(""uri"")" instead of "uri". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-json-sarif.cc:250:32: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/parser-json-sarif.cc:250:32: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-json-simple.cc:157:30: copy_constructor_call: "evt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/parser-json-simple.cc:157:30: remediation: Use "std::move(""evt"")" instead of "evt". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-json-zap.cc:144:9: copy_assignment_call: "version" is copied in call to copy assignment for class "std::string const", when it could be moved instead. src/lib/parser-json-zap.cc:144:49: remediation: Use "std::move(""version"")" instead of "version". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-xml-valgrind.cc:61:9: copy_assignment_call: "argVal" is copied in call to copy assignment for class "std::string const", when it could be moved instead. src/lib/parser-xml-valgrind.cc:61:17: remediation: Use "std::move(""argVal"")" instead of "argVal". Error: COPY_INSTEAD_OF_MOVE: src/lib/parser-xml-valgrind.cc:227:32: copy_constructor_call: "noteEvt" is copied and then passed-by-reference as parameter to STL insertion function "std::vector<DefEvent, std::allocator<DefEvent> >::push_back(std::vector<DefEvent, std::allocator<DefEvent> >::value_type const &)", when it could be moved instead. src/lib/parser-xml-valgrind.cc:227:32: remediation: Use "std::move(""noteEvt"")" instead of "noteEvt". ``` Related: #216
1 parent 72e1aca commit ba468e9

7 files changed

+11
-11
lines changed

Diff for: src/lib/filter.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void appendCtxLines(
111111
evt.event = "#";
112112
evt.msg = str.str();
113113
evt.verbosityLevel = /* not a key event */ 1;
114-
pDst->push_back(evt);
114+
pDst->push_back(std::move(evt));
115115
}
116116
}
117117

@@ -202,7 +202,7 @@ bool DuplicateFilter::matchDef(const Defect &def)
202202
evt.fileName = MsgFilter::inst().filterPath(evt.fileName);
203203
evt.msg = MsgFilter::inst().filterMsg(evt.msg, def.checker);
204204

205-
return d->lookup.insert(evt)./* inserted */second;
205+
return d->lookup.insert(std::move(evt))./* inserted */second;
206206
}
207207

208208

Diff for: src/lib/parser-cov.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ bool KeyEventDigger::guessKeyEvent(Defect *def)
425425
// no override for the checker -> match the lowered checker name
426426
std::string str(def->checker);
427427
boost::algorithm::to_lower(str);
428-
defKeyEvent.insert(str);
428+
defKeyEvent.insert(std::move(str));
429429
}
430430

431431
// look for an explicitly defined key event

Diff for: src/lib/parser-gcc.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,13 @@ bool BasicGccParser::getNext(Defect *pDef)
549549
case T_INC:
550550
case T_SCOPE:
551551
done = this->exportAndReset(pDef);
552-
defCurrent_.events.push_back(evt);
552+
defCurrent_.events.push_back(std::move(evt));
553553
break;
554554

555555
case T_MSG:
556556
done = this->exportAndReset(pDef);
557557
defCurrent_.keyEventIdx = defCurrent_.events.size();
558-
defCurrent_.events.push_back(evt);
558+
defCurrent_.events.push_back(std::move(evt));
559559
hasKeyEvent_ = true;
560560
break;
561561

Diff for: src/lib/parser-json-sarif.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void sarifReadLocation(DefEvent *pEvt, const pt::ptree &loc)
202202
const auto uri = valueOf<std::string>(*al, "uri");
203203
if (!uri.empty())
204204
// read file name
205-
pEvt->fileName = uri;
205+
pEvt->fileName = std::move(uri);
206206
}
207207

208208
const pt::ptree *reg;
@@ -247,7 +247,7 @@ static void sarifReadComments(Defect *pDef, const pt::ptree &relatedLocs)
247247
continue;
248248

249249
evt.verbosityLevel = 1;
250-
pDef->events.push_back(evt);
250+
pDef->events.push_back(std::move(evt));
251251
}
252252
}
253253

Diff for: src/lib/parser-json-simple.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool SimpleTreeDecoder::readNode(Defect *def)
154154
if (-1 == evt.verbosityLevel)
155155
verbosityLevelNeedsInit = true;
156156

157-
evtListDst.push_back(evt);
157+
evtListDst.push_back(std::move(evt));
158158
}
159159

160160
// read "defect_id", "cwe", and "function" if available

Diff for: src/lib/parser-json-zap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void ZapTreeDecoder::readScanProps(
141141
{
142142
const auto version = valueOf<std::string>(*root, "@version");
143143
if (!version.empty())
144-
(*pDst)["analyzer-version-owasp-zap"] = version;
144+
(*pDst)["analyzer-version-owasp-zap"] = std::move(version);
145145

146146
d->timeStamp = valueOf<std::string>(*root, "@generated");
147147
}

Diff for: src/lib/parser-xml-valgrind.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool /* continue */ skipLdArgs(
5858
goto skip_arg;
5959

6060
// record path of the real binary being executed
61-
*pExe = argVal;
61+
*pExe = std::move(argVal);
6262
++(*pIt);
6363
return /* continue */ (itEnd != *pIt);
6464

@@ -224,7 +224,7 @@ void readStack(Defect *pDef, const pt::ptree &stackNode)
224224
}
225225

226226
// finally push the "note" event
227-
pDef->events.push_back(noteEvt);
227+
pDef->events.push_back(std::move(noteEvt));
228228
}
229229
}
230230

0 commit comments

Comments
 (0)