More std::move changes based on Coverity findings

This commit is contained in:
Tim Wojtulewicz 2025-04-04 15:11:17 -07:00
parent 2390625732
commit 34ee136a3c
19 changed files with 48 additions and 45 deletions

View file

@ -122,7 +122,7 @@ void DebugLogger::EnableStreams(const char* s) {
for ( i = 0; i < NUM_DBGS; ++i ) { for ( i = 0; i < NUM_DBGS; ++i ) {
if ( ltok == streams[i].prefix ) { if ( ltok == streams[i].prefix ) {
streams[i].enabled = true; streams[i].enabled = true;
enabled_streams.insert(ltok); enabled_streams.insert(std::move(ltok));
goto next; goto next;
} }
} }

View file

@ -38,7 +38,7 @@ void EventRegistry::Register(EventHandlerPtr handler, bool is_from_script) {
handlers[name] = std::unique_ptr<EventHandler>(handler.Ptr()); handlers[name] = std::unique_ptr<EventHandler>(handler.Ptr());
if ( ! is_from_script ) if ( ! is_from_script )
not_only_from_script.insert(name); not_only_from_script.insert(std::move(name));
} }
EventHandler* EventRegistry::Lookup(std::string_view name) { EventHandler* EventRegistry::Lookup(std::string_view name) {

View file

@ -831,7 +831,7 @@ void ValTraceMgr::AssessChange(const ValTrace* vt, const ValTrace* prev_vt) {
if ( previous_deltas.count(full_delta) > 0 ) if ( previous_deltas.count(full_delta) > 0 )
continue; continue;
previous_deltas.insert(full_delta); previous_deltas.insert(std::move(full_delta));
ValUsed(vp); ValUsed(vp);
curr_ev->AddDelta(vp, rhs, needs_lhs, is_first_def); curr_ev->AddDelta(vp, rhs, needs_lhs, is_first_def);

View file

@ -288,7 +288,7 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, std::vector<StmtPtr> b
Body b; Body b;
b.stmts = std::move(bs[i]); b.stmts = std::move(bs[i]);
b.priority = priorities[i]; b.priority = priorities[i];
bodies.push_back(b); bodies.push_back(std::move(b));
} }
std::stable_sort(bodies.begin(), bodies.end()); std::stable_sort(bodies.begin(), bodies.end());
@ -564,7 +564,7 @@ void ScriptFunc::AddBody(StmtPtr new_body, const std::vector<IDPtr>& new_inits,
current_body = new_body; current_body = new_body;
current_priority = b.priority = priority; current_priority = b.priority = priority;
bodies.push_back(b); bodies.push_back(std::move(b));
std::stable_sort(bodies.begin(), bodies.end()); std::stable_sort(bodies.begin(), bodies.end());
} }
@ -898,7 +898,7 @@ FunctionIngredients::FunctionIngredients(ScopePtr _scope, StmtPtr _body, const s
auto flavor = id->GetType<zeek::FuncType>()->Flavor(); auto flavor = id->GetType<zeek::FuncType>()->Flavor();
if ( flavor == FUNC_FLAVOR_EVENT || flavor == FUNC_FLAVOR_HOOK ) { if ( flavor == FUNC_FLAVOR_EVENT || flavor == FUNC_FLAVOR_HOOK ) {
auto module_group = event_registry->RegisterGroup(EventGroupKind::Module, module_name); auto module_group = event_registry->RegisterGroup(EventGroupKind::Module, module_name);
groups.insert(module_group); groups.insert(std::move(module_group));
} }
} }
@ -912,7 +912,7 @@ zeek::RecordValPtr make_backtrace_element(std::string_view name, const VectorVal
auto elem = make_intrusive<RecordVal>(elem_type); auto elem = make_intrusive<RecordVal>(elem_type);
elem->Assign(function_name_idx, name.data()); elem->Assign(function_name_idx, name.data());
elem->Assign(function_args_idx, std::move(args)); elem->Assign(function_args_idx, args);
if ( loc ) { if ( loc ) {
elem->Assign(file_location_idx, loc->filename); elem->Assign(file_location_idx, loc->filename);

View file

@ -1607,7 +1607,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek
void EnumType::AddNameInternal(const string& module_name, const char* name, zeek_int_t val, bool is_export) { void EnumType::AddNameInternal(const string& module_name, const char* name, zeek_int_t val, bool is_export) {
string fullname = detail::make_full_var_name(module_name.c_str(), name); string fullname = detail::make_full_var_name(module_name.c_str(), name);
names[fullname] = val; names[fullname] = val;
rev_names[val] = fullname; rev_names[val] = std::move(fullname);
} }
void EnumType::AddNameInternal(const string& full_name, zeek_int_t val) { void EnumType::AddNameInternal(const string& full_name, zeek_int_t val) {

View file

@ -468,6 +468,8 @@ TEST_CASE("construction") {
zeek::String s5{std::string("abcdef")}; zeek::String s5{std::string("abcdef")};
CHECK_EQ(s5.Len(), 6); CHECK_EQ(s5.Len(), 6);
// Test the copy constructor.
// coverity[copy_instead_of_move]
zeek::String s6{s5}; zeek::String s6{s5};
CHECK_EQ(s6.Len(), 6); CHECK_EQ(s6.Len(), 6);

View file

@ -998,7 +998,7 @@ vector<string> IRC_Analyzer::SplitWords(const string& input, char split) {
// Add line end if needed. // Add line end if needed.
if ( start < input.size() ) { if ( start < input.size() ) {
word = input.substr(start, input.size() - start); word = input.substr(start, input.size() - start);
words.push_back(word); words.push_back(std::move(word));
} }
return words; return words;

View file

@ -815,7 +815,7 @@ std::vector<std::string> POP3_Analyzer::TokenizeLine(const std::string& input, c
tokens.push_back(token); tokens.push_back(token);
token = input.substr(splitPos + 1, input.size() - splitPos); token = input.substr(splitPos + 1, input.size() - splitPos);
tokens.push_back(token); tokens.push_back(std::move(token));
} }
return tokens; return tokens;

View file

@ -95,7 +95,7 @@ zeek::ValPtr publish_event(const zeek::ValPtr& topic, zeek::ArgsSpan args) {
return zeek::val_mgr->False(); return zeek::val_mgr->False();
} }
const auto topic_str = topic->AsStringVal()->ToStdString(); auto topic_str = topic->AsStringVal()->ToStdString();
auto timestamp = zeek::event_mgr.CurrentEventTime(); auto timestamp = zeek::event_mgr.CurrentEventTime();
@ -126,7 +126,7 @@ zeek::ValPtr publish_event(const zeek::ValPtr& topic, zeek::ArgsSpan args) {
return zeek::val_mgr->False(); return zeek::val_mgr->False();
} }
return zeek::val_mgr->Bool(zeek::broker_mgr->PublishEvent(topic_str, args[0]->AsRecordVal())); return zeek::val_mgr->Bool(zeek::broker_mgr->PublishEvent(std::move(topic_str), args[0]->AsRecordVal()));
} }
else { else {
zeek::emit_builtin_error(zeek::util::fmt("Publish of unknown record type '%s'", zeek::emit_builtin_error(zeek::util::fmt("Publish of unknown record type '%s'",

View file

@ -124,8 +124,9 @@ std::unique_ptr<WebSocketServer> StartServer(std::unique_ptr<WebSocketEventDispa
// These callbacks run in per client threads. The actual processing happens // These callbacks run in per client threads. The actual processing happens
// on the main thread via a single WebSocketDemux instance. // on the main thread via a single WebSocketDemux instance.
ix::OnMessageCallback message_callback = [dispatcher, id, remotePort, remoteIp, ix::OnMessageCallback message_callback = [dispatcher, id = std::move(id), remotePort,
ixws](const ix::WebSocketMessagePtr& msg) mutable { remoteIp = std::move(remoteIp),
ixws = std::move(ixws)](const ix::WebSocketMessagePtr& msg) mutable {
if ( msg->type == ix::WebSocketMessageType::Open ) { if ( msg->type == ix::WebSocketMessageType::Open ) {
dispatcher->QueueForProcessing( dispatcher->QueueForProcessing(
WebSocketOpen{id, msg->openInfo.uri, msg->openInfo.protocol, std::move(ixws)}); WebSocketOpen{id, msg->openInfo.uri, msg->openInfo.protocol, std::move(ixws)});

View file

@ -287,7 +287,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
if ( util::is_file(init) ) { if ( util::is_file(init) ) {
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
scripts_to_load.push_back(init); scripts_to_load.push_back(std::move(init));
} }
// Load {bif,scripts}/__load__.zeek automatically. // Load {bif,scripts}/__load__.zeek automatically.
@ -295,14 +295,14 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
if ( util::is_file(init) ) { if ( util::is_file(init) ) {
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
scripts_to_load.push_back(init); scripts_to_load.push_back(std::move(init));
} }
init = dir + "scripts/__load__.zeek"; init = dir + "scripts/__load__.zeek";
if ( util::is_file(init) ) { if ( util::is_file(init) ) {
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
scripts_to_load.push_back(init); scripts_to_load.push_back(std::move(init));
} }
// Mark this plugin as activated by clearing the path. // Mark this plugin as activated by clearing the path.
@ -426,7 +426,7 @@ void Manager::ExtendZeekPathForPlugins() {
continue; continue;
DBG_LOG(DBG_PLUGINS, " Adding %s to ZEEKPATH", script_dir.c_str()); DBG_LOG(DBG_PLUGINS, " Adding %s to ZEEKPATH", script_dir.c_str());
path_additions.push_back(script_dir); path_additions.push_back(std::move(script_dir));
} catch ( const std::regex_error& e ) { } catch ( const std::regex_error& e ) {
// This really shouldn't ever happen, but we do need to catch the exception. // This really shouldn't ever happen, but we do need to catch the exception.
// Report a fatal error because something is wrong if this occurs. // Report a fatal error because something is wrong if this occurs.

View file

@ -35,7 +35,7 @@ void CPPCompile::CreateGlobal(const ID* g) {
auto gi = GenerateGlobalInit(g); auto gi = GenerateGlobalInit(g);
global_id_info->AddInstance(gi); global_id_info->AddInstance(gi);
global_gis[g] = gi; global_gis[g] = std::move(gi);
} }
if ( is_bif ) if ( is_bif )

View file

@ -471,7 +471,7 @@ static void generate_CPP(std::shared_ptr<ProfileFuncs> pfs) {
const bool standalone = analysis_options.gen_standalone_CPP; const bool standalone = analysis_options.gen_standalone_CPP;
const bool report = analysis_options.report_uncompilable; const bool report = analysis_options.report_uncompilable;
CPPCompile cpp(funcs, pfs, gen_name, standalone, report); CPPCompile cpp(funcs, std::move(pfs), gen_name, standalone, report);
} }
static void analyze_scripts_for_ZAM(std::shared_ptr<ProfileFuncs> pfs) { static void analyze_scripts_for_ZAM(std::shared_ptr<ProfileFuncs> pfs) {
@ -655,7 +655,7 @@ void analyze_scripts(bool no_unused_warnings) {
reporter->FatalError("-O ZAM and -O gen-C++ conflict"); reporter->FatalError("-O ZAM and -O gen-C++ conflict");
auto pfs = std::make_shared<ProfileFuncs>(funcs, is_CPP_compilable, true, false); auto pfs = std::make_shared<ProfileFuncs>(funcs, is_CPP_compilable, true, false);
generate_CPP(pfs); generate_CPP(std::move(pfs));
exit(0); exit(0);
} }

View file

@ -197,16 +197,16 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
succ_UDs = PropagateUDs(s_i, succ_UDs, succ, second_pass); succ_UDs = PropagateUDs(s_i, succ_UDs, succ, second_pass);
} }
return UseUDs(s, succ_UDs); return UseUDs(s, std::move(succ_UDs));
} }
case STMT_CATCH_RETURN: { case STMT_CATCH_RETURN: {
auto cr = s->AsCatchReturnStmt(); auto cr = s->AsCatchReturnStmt();
auto block = cr->Block(); auto block = cr->Block();
auto uds = PropagateUDs(block.get(), succ_UDs, succ_stmt, second_pass); auto uds = PropagateUDs(block.get(), std::move(succ_UDs), succ_stmt, second_pass);
return UseUDs(s, uds); return UseUDs(s, std::move(uds));
} }
case STMT_NULL: case STMT_NULL:
@ -217,7 +217,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
// actually succ_stmt (other than for STMT_NULL). However, // actually succ_stmt (other than for STMT_NULL). However,
// in the contexts in which these can occur, it doesn't // in the contexts in which these can occur, it doesn't
// actually do any harm to use the successor anyway. // actually do any harm to use the successor anyway.
return UseUDs(s, succ_UDs); return UseUDs(s, std::move(succ_UDs));
case STMT_PRINT: return CreateExprUDs(s, s->AsPrintStmt()->ExprList(), succ_UDs); case STMT_PRINT: return CreateExprUDs(s, s->AsPrintStmt()->ExprList(), succ_UDs);
@ -229,7 +229,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
if ( e ) if ( e )
return CreateExprUDs(s, e, succ_UDs); return CreateExprUDs(s, e, succ_UDs);
else else
return UseUDs(s, succ_UDs); return UseUDs(s, std::move(succ_UDs));
} }
case STMT_EXPR: { case STMT_EXPR: {
@ -255,7 +255,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
if ( ! second_pass ) if ( ! second_pass )
successor[s] = succ_stmt; successor[s] = succ_stmt;
return CreateUDs(s, uds); return CreateUDs(s, std::move(uds));
} }
case STMT_IF: { case STMT_IF: {
@ -264,7 +264,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
auto cond_UDs = ExprUDs(cond); auto cond_UDs = ExprUDs(cond);
auto true_UDs = PropagateUDs(i->TrueBranch(), succ_UDs, succ_stmt, second_pass); auto true_UDs = PropagateUDs(i->TrueBranch(), succ_UDs, succ_stmt, second_pass);
auto false_UDs = PropagateUDs(i->FalseBranch(), succ_UDs, succ_stmt, second_pass); auto false_UDs = PropagateUDs(i->FalseBranch(), std::move(succ_UDs), succ_stmt, second_pass);
return CreateUDs(s, UD_Union(cond_UDs, true_UDs, false_UDs)); return CreateUDs(s, UD_Union(cond_UDs, true_UDs, false_UDs));
} }
@ -273,7 +273,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
if ( ! second_pass ) if ( ! second_pass )
successor[s] = succ_stmt; successor[s] = succ_stmt;
return UseUDs(s, succ_UDs); return UseUDs(s, std::move(succ_UDs));
case STMT_WHEN: { case STMT_WHEN: {
auto w = s->AsWhenStmt(); auto w = s->AsWhenStmt();
@ -284,7 +284,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
if ( timeout ) if ( timeout )
uds = UD_Union(uds, ExprUDs(timeout.get())); uds = UD_Union(uds, ExprUDs(timeout.get()));
return CreateUDs(s, uds); return CreateUDs(s, std::move(uds));
} }
case STMT_ASSERT: { case STMT_ASSERT: {
@ -334,7 +334,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
// keep successor definitions in the mix // keep successor definitions in the mix
FoldInUDs(sw_UDs, succ_UDs, e_UDs); FoldInUDs(sw_UDs, succ_UDs, e_UDs);
return CreateUDs(s, sw_UDs); return CreateUDs(s, std::move(sw_UDs));
} }
case STMT_FOR: { case STMT_FOR: {
@ -353,7 +353,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
// Confluence: loop the top UDs back around to the bottom. // Confluence: loop the top UDs back around to the bottom.
auto bottom_UDs = UD_Union(f_UDs, succ_UDs); auto bottom_UDs = UD_Union(f_UDs, succ_UDs);
(void)PropagateUDs(body, bottom_UDs, body, true); (void)PropagateUDs(body, std::move(bottom_UDs), body, true);
auto ids = f->LoopVars(); auto ids = f->LoopVars();
for ( const auto& id : *ids ) for ( const auto& id : *ids )
@ -366,7 +366,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
// The loop might not execute at all. // The loop might not execute at all.
FoldInUDs(f_UDs, succ_UDs); FoldInUDs(f_UDs, succ_UDs);
return CreateUDs(s, f_UDs); return CreateUDs(s, std::move(f_UDs));
} }
case STMT_WHILE: { case STMT_WHILE: {
@ -390,19 +390,19 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
// that has the correct UDs associated with it. // that has the correct UDs associated with it.
const auto& c_as_s = w->ConditionAsStmt(); const auto& c_as_s = w->ConditionAsStmt();
auto c_as_s_UDs = std::make_shared<UseDefSet>(w_UDs); auto c_as_s_UDs = std::make_shared<UseDefSet>(w_UDs);
CreateUDs(c_as_s.get(), c_as_s_UDs); CreateUDs(c_as_s.get(), std::move(c_as_s_UDs));
w_UDs = PropagateUDs(cond_stmt, w_UDs, c_as_s, second_pass); w_UDs = PropagateUDs(cond_stmt, w_UDs, c_as_s, second_pass);
} }
// Confluence: loop the top UDs back around to the bottom. // Confluence: loop the top UDs back around to the bottom.
auto bottom_UDs = UD_Union(w_UDs, succ_UDs); auto bottom_UDs = UD_Union(w_UDs, succ_UDs);
(void)PropagateUDs(body, bottom_UDs, succ, true); (void)PropagateUDs(body, std::move(bottom_UDs), succ, true);
// The loop might not execute at all. // The loop might not execute at all.
FoldInUDs(w_UDs, succ_UDs); FoldInUDs(w_UDs, succ_UDs);
return CreateUDs(s, w_UDs); return CreateUDs(s, std::move(w_UDs));
} }
default: reporter->InternalError("non-reduced statement in use-def analysis"); default: reporter->InternalError("non-reduced statement in use-def analysis");

View file

@ -722,7 +722,7 @@ void ZAMCompiler::ReMapVar(const ID* id, int slot, zeek_uint_t inst) {
FrameSharingInfo info; FrameSharingInfo info;
info.is_managed = is_managed; info.is_managed = is_managed;
shared_frame_denizens.push_back(info); shared_frame_denizens.push_back(std::move(info));
if ( is_managed ) if ( is_managed )
managed_slotsI.push_back(apt_slot); managed_slotsI.push_back(apt_slot);

View file

@ -329,7 +329,7 @@ void ZAMCompiler::CreateSharedFrameDenizens() {
// execution. // execution.
info.is_managed = false; info.is_managed = false;
shared_frame_denizens_final.push_back(info); shared_frame_denizens_final.push_back(std::move(info));
} }
} }

View file

@ -542,24 +542,24 @@ const ZAMStmt ZAMCompiler::GenSwitch(const SwitchStmt* sw, int slot, InternalTyp
switch ( it ) { switch ( it ) {
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
tbl = int_casesI.size(); tbl = int_casesI.size();
int_casesI.push_back(new_int_cases); int_casesI.push_back(std::move(new_int_cases));
break; break;
case TYPE_INTERNAL_UNSIGNED: case TYPE_INTERNAL_UNSIGNED:
tbl = uint_casesI.size(); tbl = uint_casesI.size();
uint_casesI.push_back(new_uint_cases); uint_casesI.push_back(std::move(new_uint_cases));
break; break;
case TYPE_INTERNAL_DOUBLE: case TYPE_INTERNAL_DOUBLE:
tbl = double_casesI.size(); tbl = double_casesI.size();
double_casesI.push_back(new_double_cases); double_casesI.push_back(std::move(new_double_cases));
break; break;
case TYPE_INTERNAL_STRING: case TYPE_INTERNAL_STRING:
case TYPE_INTERNAL_ADDR: case TYPE_INTERNAL_ADDR:
case TYPE_INTERNAL_SUBNET: case TYPE_INTERNAL_SUBNET:
tbl = str_casesI.size(); tbl = str_casesI.size();
str_casesI.push_back(new_str_cases); str_casesI.push_back(std::move(new_str_cases));
break; break;
default: reporter->InternalError("bad switch type"); default: reporter->InternalError("bad switch type");

View file

@ -31,7 +31,7 @@ class TelemetryValImpl : public TelemetryVal {
public: public:
using HandleType = std::shared_ptr<Handle>; using HandleType = std::shared_ptr<Handle>;
explicit TelemetryValImpl(HandleType hdl) : TelemetryVal(hdl), hdl(hdl) {} explicit TelemetryValImpl(HandleType hdl) : TelemetryVal(hdl), hdl(std::move(hdl)) {}
HandleType GetHandle() const noexcept { return hdl; } HandleType GetHandle() const noexcept { return hdl; }

View file

@ -599,11 +599,11 @@ template<typename T>
std::vector<T> split(T s, const T& delim) { std::vector<T> split(T s, const T& delim) {
// If there's no delimiter, return a copy of the existing string. // If there's no delimiter, return a copy of the existing string.
if ( delim.empty() ) if ( delim.empty() )
return {T(s)}; return {std::move(s)};
// If the delimiter won't fit in the string, just return a copy as well. // If the delimiter won't fit in the string, just return a copy as well.
if ( s.size() < delim.size() ) if ( s.size() < delim.size() )
return {T(s)}; return {std::move(s)};
std::vector<T> l; std::vector<T> l;