Fix clang-tidy modernize-pass-by-value findings

This commit is contained in:
Tim Wojtulewicz 2025-05-15 09:25:39 -07:00
parent 46e67a749a
commit 5930d2f944
22 changed files with 37 additions and 40 deletions

View file

@ -5,6 +5,7 @@ Checks: [-*,
modernize-loop-convert, modernize-loop-convert,
modernize-make-unique, modernize-make-unique,
modernize-min-max-use-initializer-list, modernize-min-max-use-initializer-list,
modernize-pass-by-value,
# Enable a very limited number of the cppcoreguidelines checkers. # Enable a very limited number of the cppcoreguidelines checkers.
# See the notes for some of the rest of them below. # See the notes for some of the rest of them below.

View file

@ -51,7 +51,7 @@ static std::string escape_string(const u_char* b, int len) {
return res + "\""; return res + "\"";
} }
ValTrace::ValTrace(const ValPtr& _v) : v(_v) { ValTrace::ValTrace(ValPtr _v) : v(std::move(_v)) {
t = v->GetType(); t = v->GetType();
switch ( t->Tag() ) { switch ( t->Tag() ) {

View file

@ -45,7 +45,7 @@ using DeltaVector = std::vector<std::unique_ptr<ValDelta>>;
// be readily compared against future instances. // be readily compared against future instances.
class ValTrace { class ValTrace {
public: public:
ValTrace(const ValPtr& v); ValTrace(ValPtr v);
~ValTrace() = default; ~ValTrace() = default;
const ValPtr& GetVal() const { return v; } const ValPtr& GetVal() const { return v; }

View file

@ -24,7 +24,7 @@ void Analyzer::SetAnalyzerTag(const zeek::Tag& arg_tag) {
} }
Analyzer::Analyzer(zeek::Tag arg_tag, RecordValPtr arg_args, File* arg_file) 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)), args(std::move(arg_args)),
file(arg_file), file(arg_file),
got_stream_delivery(false), got_stream_delivery(false),

View file

@ -7,8 +7,8 @@
namespace zeek::file_analysis::detail { namespace zeek::file_analysis::detail {
FileTimer::FileTimer(double t, const std::string& id, double interval) FileTimer::FileTimer(double t, std::string id, double interval)
: zeek::detail::Timer(t + interval, zeek::detail::TIMER_FILE_ANALYSIS_INACTIVITY), file_id(id) { : 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()); DBG_LOG(DBG_FILE_ANALYSIS, "New %f second timeout timer for %s", interval, file_id.c_str());
} }

View file

@ -19,7 +19,7 @@ public:
* @param id the file identifier which will be checked for inactivity. * @param id the file identifier which will be checked for inactivity.
* @param interval amount of time after \a t to check 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, * Check inactivity of file_analysis::File corresponding to #file_id,

View file

@ -11,10 +11,10 @@
namespace zeek::file_analysis::detail { 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) bool arg_limit_includes_missing)
: file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), std::move(args), file), : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), std::move(args), file),
filename(arg_filename), filename(std::move(arg_filename)),
limit(arg_limit), limit(arg_limit),
written(0), written(0),
limit_includes_missing(arg_limit_includes_missing) { limit_includes_missing(arg_limit_includes_missing) {

View file

@ -64,7 +64,7 @@ protected:
* @param arg_limit the maximum allowed file size. * @param arg_limit the maximum allowed file size.
* @param arg_limit_includes_missing missing bytes count towards limit if true. * @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); bool arg_limit_includes_missing);
private: private:

View file

@ -17,17 +17,14 @@ using zeek::threading::Value;
namespace zeek::input::reader::detail { namespace zeek::input::reader::detail {
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position) FieldMapping::FieldMapping(string arg_name, const TypeTag& arg_type, int arg_position)
: name(arg_name), type(arg_type), subtype(TYPE_ERROR) { : name(std::move(arg_name)), type(arg_type), subtype(TYPE_ERROR), position(arg_position) {
position = arg_position;
secondary_position = -1; secondary_position = -1;
present = true; present = true;
} }
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, FieldMapping::FieldMapping(string arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position)
int arg_position) : name(std::move(arg_name)), type(arg_type), subtype(arg_subtype), position(arg_position) {
: name(arg_name), type(arg_type), subtype(arg_subtype) {
position = arg_position;
secondary_position = -1; secondary_position = -1;
present = true; present = true;
} }

View file

@ -23,8 +23,8 @@ struct FieldMapping {
int secondary_position = -1; // for ports: pos of the second field int secondary_position = -1; // for ports: pos of the second field
bool present = false; bool present = false;
FieldMapping(const std::string& arg_name, const TypeTag& arg_type, int arg_position); FieldMapping(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, const TypeTag& arg_subtype, int arg_position);
FieldMapping(const FieldMapping& arg); FieldMapping(const FieldMapping& arg);
FieldMapping() = default; FieldMapping() = default;

View file

@ -108,8 +108,8 @@ class DelayInfo {
public: public:
static const DelayInfoPtr nil; static const DelayInfoPtr nil;
explicit DelayInfo(const WriteContext& ctx, const zeek::ValPtr token_val, double expire_time) explicit DelayInfo(WriteContext ctx, const zeek::ValPtr token_val, double expire_time)
: ctx(ctx), token_val(token_val), expire_time(expire_time) {} : ctx(std::move(ctx)), token_val(token_val), expire_time(expire_time) {}
// No copy or assignment of DelayInfo itself, should // No copy or assignment of DelayInfo itself, should
// always be managed through a shared pointer. // always be managed through a shared pointer.

View file

@ -11,9 +11,8 @@ namespace zeek::plugin {
Tag::type_t Component::type_counter(0); Tag::type_t Component::type_counter(0);
Component::Component(component::Type arg_type, const std::string& arg_name, Tag::subtype_t tag_subtype, Component::Component(component::Type arg_type, std::string arg_name, Tag::subtype_t tag_subtype, EnumTypePtr etype)
EnumTypePtr etype) : type(arg_type), name(std::move(arg_name)), tag(etype, 1, 0), etype(std::move(etype)), tag_subtype(tag_subtype) {
: type(arg_type), name(arg_name), tag(etype, 1, 0), etype(std::move(etype)), tag_subtype(tag_subtype) {
canon_name = util::canonify_name(name); canon_name = util::canonify_name(name);
canon_name_val = make_intrusive<StringVal>(canon_name); canon_name_val = make_intrusive<StringVal>(canon_name);
} }

View file

@ -66,8 +66,7 @@ public:
* @param etype An enum type that describes the type for the tag in * @param etype An enum type that describes the type for the tag in
* script-land. * script-land.
*/ */
Component(component::Type type, const std::string& name, Tag::subtype_t tag_subtype = 0, Component(component::Type type, std::string name, Tag::subtype_t tag_subtype = 0, EnumTypePtr etype = nullptr);
EnumTypePtr etype = nullptr);
/** /**
* Destructor. * Destructor.

View file

@ -21,8 +21,8 @@ namespace {
class Tracer { class Tracer {
public: public:
Tracer(const std::string& where) : where(where) {} // DBG_LOG(zeek::DBG_STORAGE, "%s", 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()); } ~Tracer() {} // DBG_LOG(zeek::DBG_STORAGE, "%s done", where.c_str()); }
std::string where; std::string where;
}; };

View file

@ -29,8 +29,8 @@ static TargetFactory create_target_factory() {
return rval; return rval;
} }
Config::Config(const string& arg_file, const string& delim) Config::Config(string arg_file, const string& delim)
: file(arg_file), targets(), target_factory(create_target_factory()) { : file(std::move(arg_file)), targets(), target_factory(create_target_factory()) {
if ( file.empty() ) if ( file.empty() )
return; return;

View file

@ -26,7 +26,7 @@ public:
* an empty string most methods are a no-op. * an empty string most methods are a no-op.
* @param delim The delimiter between target fields. * @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. * Destructor, cleans up targets created when parsing config file.

View file

@ -12,7 +12,7 @@ using namespace std;
namespace zeek::zeekygen::detail { 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()); string readme_file = util::find_file(pkg_name + "/README", util::zeek_path());
if ( readme_file.empty() ) if ( readme_file.empty() )

View file

@ -20,7 +20,7 @@ public:
* @param name The name of the Zeek script package (relative path from a * @param name The name of the Zeek script package (relative path from a
* component within ZEEKPATH). * 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 * @return The content of the package's README file, each line being

View file

@ -221,10 +221,10 @@ static string make_redef_details(const string& heading, char underline, const id
return rval; return rval;
} }
ScriptInfo::ScriptInfo(const string& arg_name, const string& arg_path) ScriptInfo::ScriptInfo(string arg_name, string arg_path)
: Info(), : Info(),
name(arg_name), name(std::move(arg_name)),
path(arg_path), path(std::move(arg_path)),
is_pkg_loader(util::detail::is_package_loader(name)), is_pkg_loader(util::detail::is_package_loader(name)),
dependencies(), dependencies(),
module_usages(), module_usages(),

View file

@ -32,7 +32,7 @@ public:
* @param name Name of script: a path relative to a component in ZEEKPATH. * @param name Name of script: a path relative to a component in ZEEKPATH.
* @param path Absolute path to the script. * @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. * Associate a Zeekygen summary comment ("##!") with the script.

View file

@ -189,7 +189,7 @@ static vector<T*> filter_matches(const vector<Info*>& from, Target* t) {
return rval; 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 ) { if ( name.find('/') != string::npos ) {
string dir = util::SafeDirname(name).result; 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()); 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('*'); size_t pos = pattern.find('*');
if ( pos == 0 || pos == string::npos ) if ( pos == 0 || pos == string::npos )

View file

@ -28,7 +28,7 @@ struct TargetFile {
* directories that don't already exist. * directories that don't already exist.
* *
*/ */
explicit TargetFile(const std::string& arg_name); explicit TargetFile(std::string arg_name);
/** /**
* Close the file. * Close the file.
@ -53,7 +53,7 @@ public:
* @param arg_pattern pattern of info objects the target depends upon. Only * @param arg_pattern pattern of info objects the target depends upon. Only
* exact string and simple prefix matching is currently allowed. * 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. * Dtor.