Skip to content

Commit

Permalink
lib: use std::move() where appropriate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kdudka committed Dec 12, 2024
1 parent 72e1aca commit ba468e9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void appendCtxLines(
evt.event = "#";
evt.msg = str.str();
evt.verbosityLevel = /* not a key event */ 1;
pDst->push_back(evt);
pDst->push_back(std::move(evt));
}
}

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

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


Expand Down
2 changes: 1 addition & 1 deletion src/lib/parser-cov.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ bool KeyEventDigger::guessKeyEvent(Defect *def)
// no override for the checker -> match the lowered checker name
std::string str(def->checker);
boost::algorithm::to_lower(str);
defKeyEvent.insert(str);
defKeyEvent.insert(std::move(str));
}

// look for an explicitly defined key event
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parser-gcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,13 @@ bool BasicGccParser::getNext(Defect *pDef)
case T_INC:
case T_SCOPE:
done = this->exportAndReset(pDef);
defCurrent_.events.push_back(evt);
defCurrent_.events.push_back(std::move(evt));
break;

case T_MSG:
done = this->exportAndReset(pDef);
defCurrent_.keyEventIdx = defCurrent_.events.size();
defCurrent_.events.push_back(evt);
defCurrent_.events.push_back(std::move(evt));
hasKeyEvent_ = true;
break;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/parser-json-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void sarifReadLocation(DefEvent *pEvt, const pt::ptree &loc)
const auto uri = valueOf<std::string>(*al, "uri");
if (!uri.empty())
// read file name
pEvt->fileName = uri;
pEvt->fileName = std::move(uri);
}

const pt::ptree *reg;
Expand Down Expand Up @@ -247,7 +247,7 @@ static void sarifReadComments(Defect *pDef, const pt::ptree &relatedLocs)
continue;

evt.verbosityLevel = 1;
pDef->events.push_back(evt);
pDef->events.push_back(std::move(evt));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/parser-json-simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool SimpleTreeDecoder::readNode(Defect *def)
if (-1 == evt.verbosityLevel)
verbosityLevelNeedsInit = true;

evtListDst.push_back(evt);
evtListDst.push_back(std::move(evt));
}

// read "defect_id", "cwe", and "function" if available
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parser-json-zap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void ZapTreeDecoder::readScanProps(
{
const auto version = valueOf<std::string>(*root, "@version");
if (!version.empty())
(*pDst)["analyzer-version-owasp-zap"] = version;
(*pDst)["analyzer-version-owasp-zap"] = std::move(version);

d->timeStamp = valueOf<std::string>(*root, "@generated");
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parser-xml-valgrind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool /* continue */ skipLdArgs(
goto skip_arg;

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

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

// finally push the "note" event
pDef->events.push_back(noteEvt);
pDef->events.push_back(std::move(noteEvt));
}
}

Expand Down

0 comments on commit ba468e9

Please sign in to comment.