From 5930d2f94454636fd193811a243554729a495f4d Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 15 May 2025 09:25:39 -0700 Subject: [PATCH] Fix clang-tidy modernize-pass-by-value findings --- .clang-tidy | 1 + src/EventTrace.cc | 2 +- src/EventTrace.h | 2 +- src/file_analysis/Analyzer.cc | 2 +- src/file_analysis/FileTimer.cc | 4 ++-- src/file_analysis/FileTimer.h | 2 +- src/file_analysis/analyzer/extract/Extract.cc | 4 ++-- src/file_analysis/analyzer/extract/Extract.h | 2 +- src/input/readers/ascii/Ascii.cc | 11 ++++------- src/input/readers/ascii/Ascii.h | 4 ++-- src/logging/Manager.cc | 4 ++-- src/plugin/Component.cc | 5 ++--- src/plugin/Component.h | 3 +-- src/storage/backend/redis/Redis.cc | 4 ++-- src/zeekygen/Configuration.cc | 4 ++-- src/zeekygen/Configuration.h | 2 +- src/zeekygen/PackageInfo.cc | 2 +- src/zeekygen/PackageInfo.h | 2 +- src/zeekygen/ScriptInfo.cc | 6 +++--- src/zeekygen/ScriptInfo.h | 2 +- src/zeekygen/Target.cc | 5 +++-- src/zeekygen/Target.h | 4 ++-- 22 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2cf5aba5a0..8ee8b690a0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: [-*, modernize-loop-convert, modernize-make-unique, modernize-min-max-use-initializer-list, + modernize-pass-by-value, # Enable a very limited number of the cppcoreguidelines checkers. # See the notes for some of the rest of them below. diff --git a/src/EventTrace.cc b/src/EventTrace.cc index c348bcd023..33301e9fb8 100644 --- a/src/EventTrace.cc +++ b/src/EventTrace.cc @@ -51,7 +51,7 @@ static std::string escape_string(const u_char* b, int len) { return res + "\""; } -ValTrace::ValTrace(const ValPtr& _v) : v(_v) { +ValTrace::ValTrace(ValPtr _v) : v(std::move(_v)) { t = v->GetType(); switch ( t->Tag() ) { diff --git a/src/EventTrace.h b/src/EventTrace.h index 2c86efb7b2..eb3bd17cd8 100644 --- a/src/EventTrace.h +++ b/src/EventTrace.h @@ -45,7 +45,7 @@ using DeltaVector = std::vector>; // be readily compared against future instances. class ValTrace { public: - ValTrace(const ValPtr& v); + ValTrace(ValPtr v); ~ValTrace() = default; const ValPtr& GetVal() const { return v; } diff --git a/src/file_analysis/Analyzer.cc b/src/file_analysis/Analyzer.cc index 913a78e5a7..c5ed3aff03 100644 --- a/src/file_analysis/Analyzer.cc +++ b/src/file_analysis/Analyzer.cc @@ -24,7 +24,7 @@ void Analyzer::SetAnalyzerTag(const zeek::Tag& arg_tag) { } Analyzer::Analyzer(zeek::Tag arg_tag, RecordValPtr arg_args, File* arg_file) - : tag(arg_tag), + : tag(std::move(arg_tag)), args(std::move(arg_args)), file(arg_file), got_stream_delivery(false), diff --git a/src/file_analysis/FileTimer.cc b/src/file_analysis/FileTimer.cc index d5714617a0..688a9e7927 100644 --- a/src/file_analysis/FileTimer.cc +++ b/src/file_analysis/FileTimer.cc @@ -7,8 +7,8 @@ namespace zeek::file_analysis::detail { -FileTimer::FileTimer(double t, const std::string& id, double interval) - : zeek::detail::Timer(t + interval, zeek::detail::TIMER_FILE_ANALYSIS_INACTIVITY), file_id(id) { +FileTimer::FileTimer(double t, std::string id, double interval) + : zeek::detail::Timer(t + interval, zeek::detail::TIMER_FILE_ANALYSIS_INACTIVITY), file_id(std::move(id)) { DBG_LOG(DBG_FILE_ANALYSIS, "New %f second timeout timer for %s", interval, file_id.c_str()); } diff --git a/src/file_analysis/FileTimer.h b/src/file_analysis/FileTimer.h index af2dac1395..690a3d6253 100644 --- a/src/file_analysis/FileTimer.h +++ b/src/file_analysis/FileTimer.h @@ -19,7 +19,7 @@ public: * @param id the file identifier which will be checked for inactivity. * @param interval amount of time after \a t to check for inactivity. */ - FileTimer(double t, const std::string& id, double interval); + FileTimer(double t, std::string id, double interval); /** * Check inactivity of file_analysis::File corresponding to #file_id, diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index 458f5f91e1..d5eb6263ac 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -11,10 +11,10 @@ namespace zeek::file_analysis::detail { -Extract::Extract(RecordValPtr args, file_analysis::File* file, const std::string& arg_filename, uint64_t arg_limit, +Extract::Extract(RecordValPtr args, file_analysis::File* file, std::string arg_filename, uint64_t arg_limit, bool arg_limit_includes_missing) : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), std::move(args), file), - filename(arg_filename), + filename(std::move(arg_filename)), limit(arg_limit), written(0), limit_includes_missing(arg_limit_includes_missing) { diff --git a/src/file_analysis/analyzer/extract/Extract.h b/src/file_analysis/analyzer/extract/Extract.h index 4d11047655..733bb91527 100644 --- a/src/file_analysis/analyzer/extract/Extract.h +++ b/src/file_analysis/analyzer/extract/Extract.h @@ -64,7 +64,7 @@ protected: * @param arg_limit the maximum allowed file size. * @param arg_limit_includes_missing missing bytes count towards limit if true. */ - Extract(RecordValPtr args, file_analysis::File* file, const std::string& arg_filename, uint64_t arg_limit, + Extract(RecordValPtr args, file_analysis::File* file, std::string arg_filename, uint64_t arg_limit, bool arg_limit_includes_missing); private: diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index 0468e166e7..78f225a93d 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -17,17 +17,14 @@ using zeek::threading::Value; namespace zeek::input::reader::detail { -FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position) - : name(arg_name), type(arg_type), subtype(TYPE_ERROR) { - position = arg_position; +FieldMapping::FieldMapping(string arg_name, const TypeTag& arg_type, int arg_position) + : name(std::move(arg_name)), type(arg_type), subtype(TYPE_ERROR), position(arg_position) { secondary_position = -1; present = true; } -FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, - int arg_position) - : name(arg_name), type(arg_type), subtype(arg_subtype) { - position = arg_position; +FieldMapping::FieldMapping(string arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position) + : name(std::move(arg_name)), type(arg_type), subtype(arg_subtype), position(arg_position) { secondary_position = -1; present = true; } diff --git a/src/input/readers/ascii/Ascii.h b/src/input/readers/ascii/Ascii.h index 73aa3f84e8..a6d24e419f 100644 --- a/src/input/readers/ascii/Ascii.h +++ b/src/input/readers/ascii/Ascii.h @@ -23,8 +23,8 @@ struct FieldMapping { int secondary_position = -1; // for ports: pos of the second field bool present = false; - FieldMapping(const std::string& arg_name, const TypeTag& arg_type, int arg_position); - FieldMapping(const std::string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position); + FieldMapping(std::string arg_name, const TypeTag& arg_type, int arg_position); + FieldMapping(std::string arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position); FieldMapping(const FieldMapping& arg); FieldMapping() = default; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index fb75fb828c..ac3fc08d30 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -108,8 +108,8 @@ class DelayInfo { public: static const DelayInfoPtr nil; - explicit DelayInfo(const WriteContext& ctx, const zeek::ValPtr token_val, double expire_time) - : ctx(ctx), token_val(token_val), expire_time(expire_time) {} + explicit DelayInfo(WriteContext ctx, const zeek::ValPtr token_val, double expire_time) + : ctx(std::move(ctx)), token_val(token_val), expire_time(expire_time) {} // No copy or assignment of DelayInfo itself, should // always be managed through a shared pointer. diff --git a/src/plugin/Component.cc b/src/plugin/Component.cc index e363066dfd..6160484dcf 100644 --- a/src/plugin/Component.cc +++ b/src/plugin/Component.cc @@ -11,9 +11,8 @@ namespace zeek::plugin { Tag::type_t Component::type_counter(0); -Component::Component(component::Type arg_type, const std::string& arg_name, Tag::subtype_t tag_subtype, - EnumTypePtr etype) - : type(arg_type), name(arg_name), tag(etype, 1, 0), etype(std::move(etype)), tag_subtype(tag_subtype) { +Component::Component(component::Type arg_type, std::string arg_name, Tag::subtype_t tag_subtype, EnumTypePtr etype) + : type(arg_type), name(std::move(arg_name)), tag(etype, 1, 0), etype(std::move(etype)), tag_subtype(tag_subtype) { canon_name = util::canonify_name(name); canon_name_val = make_intrusive(canon_name); } diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 9a28d21a0d..6975f77092 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -66,8 +66,7 @@ public: * @param etype An enum type that describes the type for the tag in * script-land. */ - Component(component::Type type, const std::string& name, Tag::subtype_t tag_subtype = 0, - EnumTypePtr etype = nullptr); + Component(component::Type type, std::string name, Tag::subtype_t tag_subtype = 0, EnumTypePtr etype = nullptr); /** * Destructor. diff --git a/src/storage/backend/redis/Redis.cc b/src/storage/backend/redis/Redis.cc index 4b2fae68ab..f39d4c6030 100644 --- a/src/storage/backend/redis/Redis.cc +++ b/src/storage/backend/redis/Redis.cc @@ -21,8 +21,8 @@ namespace { class Tracer { public: - Tracer(const std::string& where) : where(where) {} // DBG_LOG(zeek::DBG_STORAGE, "%s", where.c_str()); } - ~Tracer() {} // DBG_LOG(zeek::DBG_STORAGE, "%s done", where.c_str()); } + Tracer(std::string where) : where(std::move(where)) {} // DBG_LOG(zeek::DBG_STORAGE, "%s", where.c_str()); } + ~Tracer() {} // DBG_LOG(zeek::DBG_STORAGE, "%s done", where.c_str()); } std::string where; }; diff --git a/src/zeekygen/Configuration.cc b/src/zeekygen/Configuration.cc index a2639ea71e..579b258555 100644 --- a/src/zeekygen/Configuration.cc +++ b/src/zeekygen/Configuration.cc @@ -29,8 +29,8 @@ static TargetFactory create_target_factory() { return rval; } -Config::Config(const string& arg_file, const string& delim) - : file(arg_file), targets(), target_factory(create_target_factory()) { +Config::Config(string arg_file, const string& delim) + : file(std::move(arg_file)), targets(), target_factory(create_target_factory()) { if ( file.empty() ) return; diff --git a/src/zeekygen/Configuration.h b/src/zeekygen/Configuration.h index 2256e0fde7..802001b24d 100644 --- a/src/zeekygen/Configuration.h +++ b/src/zeekygen/Configuration.h @@ -26,7 +26,7 @@ public: * an empty string most methods are a no-op. * @param delim The delimiter between target fields. */ - explicit Config(const std::string& file, const std::string& delim = "\t"); + explicit Config(std::string file, const std::string& delim = "\t"); /** * Destructor, cleans up targets created when parsing config file. diff --git a/src/zeekygen/PackageInfo.cc b/src/zeekygen/PackageInfo.cc index cfa73c14d6..062f891930 100644 --- a/src/zeekygen/PackageInfo.cc +++ b/src/zeekygen/PackageInfo.cc @@ -12,7 +12,7 @@ using namespace std; namespace zeek::zeekygen::detail { -PackageInfo::PackageInfo(const string& arg_name) : Info(), pkg_name(arg_name), readme() { +PackageInfo::PackageInfo(string arg_name) : Info(), pkg_name(std::move(arg_name)), readme() { string readme_file = util::find_file(pkg_name + "/README", util::zeek_path()); if ( readme_file.empty() ) diff --git a/src/zeekygen/PackageInfo.h b/src/zeekygen/PackageInfo.h index 574a709fe4..5f1f8c07f9 100644 --- a/src/zeekygen/PackageInfo.h +++ b/src/zeekygen/PackageInfo.h @@ -20,7 +20,7 @@ public: * @param name The name of the Zeek script package (relative path from a * component within ZEEKPATH). */ - explicit PackageInfo(const std::string& name); + explicit PackageInfo(std::string name); /** * @return The content of the package's README file, each line being diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 365af48a2f..103c7e273a 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -221,10 +221,10 @@ static string make_redef_details(const string& heading, char underline, const id return rval; } -ScriptInfo::ScriptInfo(const string& arg_name, const string& arg_path) +ScriptInfo::ScriptInfo(string arg_name, string arg_path) : Info(), - name(arg_name), - path(arg_path), + name(std::move(arg_name)), + path(std::move(arg_path)), is_pkg_loader(util::detail::is_package_loader(name)), dependencies(), module_usages(), diff --git a/src/zeekygen/ScriptInfo.h b/src/zeekygen/ScriptInfo.h index 1a1f2a0ea9..4cee34b096 100644 --- a/src/zeekygen/ScriptInfo.h +++ b/src/zeekygen/ScriptInfo.h @@ -32,7 +32,7 @@ public: * @param name Name of script: a path relative to a component in ZEEKPATH. * @param path Absolute path to the script. */ - ScriptInfo(const std::string& name, const std::string& path); + ScriptInfo(std::string name, std::string path); /** * Associate a Zeekygen summary comment ("##!") with the script. diff --git a/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index d4a133dddf..274b752ffb 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -189,7 +189,7 @@ static vector filter_matches(const vector& from, Target* t) { return rval; } -TargetFile::TargetFile(const string& arg_name) : name(arg_name), f() { +TargetFile::TargetFile(string arg_name) : name(std::move(arg_name)), f() { if ( name.find('/') != string::npos ) { string dir = util::SafeDirname(name).result; @@ -210,7 +210,8 @@ TargetFile::~TargetFile() { DBG_LOG(DBG_ZEEKYGEN, "Wrote out-of-date target '%s'", name.c_str()); } -Target::Target(const string& arg_name, const string& arg_pattern) : name(arg_name), pattern(arg_pattern), prefix() { +Target::Target(string arg_name, string arg_pattern) + : name(std::move(arg_name)), pattern(std::move(arg_pattern)), prefix() { size_t pos = pattern.find('*'); if ( pos == 0 || pos == string::npos ) diff --git a/src/zeekygen/Target.h b/src/zeekygen/Target.h index 4612869095..9251c58105 100644 --- a/src/zeekygen/Target.h +++ b/src/zeekygen/Target.h @@ -28,7 +28,7 @@ struct TargetFile { * directories that don't already exist. * */ - explicit TargetFile(const std::string& arg_name); + explicit TargetFile(std::string arg_name); /** * Close the file. @@ -53,7 +53,7 @@ public: * @param arg_pattern pattern of info objects the target depends upon. Only * exact string and simple prefix matching is currently allowed. */ - Target(const std::string& arg_name, const std::string& arg_pattern); + Target(std::string arg_name, std::string arg_pattern); /** * Dtor.