From 3629c4dc4a94bc22f907df1f5bfadca1ef15cc1c Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Wed, 12 Oct 2022 08:51:47 +0000 Subject: [PATCH] update(userspace): solve cppcheck performance suggestions Signed-off-by: Jason Dellaluce --- userspace/engine/rule_loader.cpp | 6 +++--- userspace/engine/rule_loader.h | 18 +++++++++--------- userspace/falco/configuration.cpp | 2 +- userspace/falco/configuration.h | 2 +- userspace/falco/falco_outputs.cpp | 4 ++-- userspace/falco/falco_outputs.h | 2 +- userspace/falco/grpc_server.cpp | 10 +++++----- userspace/falco/grpc_server.h | 10 +++++----- userspace/falco/outputs.h | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/userspace/engine/rule_loader.cpp b/userspace/engine/rule_loader.cpp index 9f77d395..66a5acec 100644 --- a/userspace/engine/rule_loader.cpp +++ b/userspace/engine/rule_loader.cpp @@ -58,7 +58,7 @@ rule_loader::context::context(const std::string& name) rule_loader::context::context(const YAML::Node &item, const item_type item_type, - const std::string item_name, + const std::string& item_name, const context& parent) { init(parent.name(), position(item.Mark()), item_type, item_name, parent); @@ -108,7 +108,7 @@ const std::string& rule_loader::context::name() const void rule_loader::context::init(const std::string& name, const position& pos, const item_type item_type, - const std::string item_name, + const std::string& item_name, const context& parent) { // Copy parent locations @@ -546,7 +546,7 @@ rule_loader::rule_info::rule_info(context &ctx) { } -rule_loader::rule_load_exception::rule_load_exception(falco::load_result::error_code ec, std::string msg, const context& ctx) +rule_loader::rule_load_exception::rule_load_exception(falco::load_result::error_code ec, const std::string& msg, const context& ctx) : ec(ec), msg(msg), ctx(ctx) { } diff --git a/userspace/engine/rule_loader.h b/userspace/engine/rule_loader.h index 5b8fc127..c6aa7a97 100644 --- a/userspace/engine/rule_loader.h +++ b/userspace/engine/rule_loader.h @@ -64,7 +64,7 @@ namespace rule_loader struct position { position() : pos(0), line(0), column(0) {}; - position(const YAML::Mark& mark) : pos(mark.pos), line(mark.line), column(mark.column) {}; + explicit position(const YAML::Mark& mark) : pos(mark.pos), line(mark.line), column(mark.column) {}; ~position() = default; position(position&&) = default; position& operator = (position&&) = default; @@ -80,10 +80,10 @@ namespace rule_loader { location(): item_type(context::item_type::VALUE_FOR) {} location( - const std::string n, + const std::string& n, const position& p, context::item_type i, - const std::string in): + const std::string& in): name(n), pos(p), item_type(i), item_name(in) {} location(location&&) = default; location& operator = (location&&) = default; @@ -108,10 +108,10 @@ namespace rule_loader std::string item_name; }; - context(const std::string& name); + explicit context(const std::string& name); context(const YAML::Node& item, item_type item_type, - const std::string item_name, + const std::string& item_name, const context& parent); // Build a context from a condition expression + @@ -152,7 +152,7 @@ namespace rule_loader void init(const std::string& name, const position& pos, const item_type item_type, - const std::string item_name, + const std::string& item_name, const context& parent); // A chain of locations from the current item, its @@ -202,7 +202,7 @@ namespace rule_loader class rule_load_exception : public std::exception { public: - rule_load_exception(falco::load_result::error_code ec, std::string msg, const context& ctx); + rule_load_exception(falco::load_result::error_code ec, const std::string& msg, const context& ctx); virtual ~rule_load_exception(); rule_load_exception(rule_load_exception&&) = default; rule_load_exception& operator = (rule_load_exception&&) = default; @@ -267,7 +267,7 @@ namespace rule_loader explicit configuration( const std::string& cont, const indexed_vector& srcs, - std::string name) + const std::string& name) : content(cont), sources(srcs), name(name), default_ruleset_id(0), replace_output_container_info(false), min_priority(falco_common::PRIORITY_DEBUG) @@ -313,7 +313,7 @@ namespace rule_loader struct requirement { requirement() = default; - requirement(const std::string n, const std::string v): + requirement(const std::string& n, const std::string& v): name(n), version(v) { } requirement(requirement&&) = default; requirement& operator = (requirement&&) = default; diff --git a/userspace/falco/configuration.cpp b/userspace/falco/configuration.cpp index bd43fa32..6aa2a320 100644 --- a/userspace/falco/configuration.cpp +++ b/userspace/falco/configuration.cpp @@ -51,7 +51,7 @@ falco_configuration::~falco_configuration() } } -void falco_configuration::init(string conf_filename, const vector &cmdline_options) +void falco_configuration::init(const string& conf_filename, const vector &cmdline_options) { string m_config_file = conf_filename; m_config = new yaml_configuration(); diff --git a/userspace/falco/configuration.h b/userspace/falco/configuration.h index 980b2968..54e57a78 100644 --- a/userspace/falco/configuration.h +++ b/userspace/falco/configuration.h @@ -216,7 +216,7 @@ public: falco_configuration(); virtual ~falco_configuration(); - void init(std::string conf_filename, const std::vector& cmdline_options); + void init(const std::string& conf_filename, const std::vector& cmdline_options); void init(const std::vector& cmdline_options); static void read_rules_file_directory(const string& path, list& rules_filenames, list &rules_folders); diff --git a/userspace/falco/falco_outputs.cpp b/userspace/falco/falco_outputs.cpp index 99b358c6..dc070731 100644 --- a/userspace/falco/falco_outputs.cpp +++ b/userspace/falco/falco_outputs.cpp @@ -50,7 +50,7 @@ falco_outputs::falco_outputs( uint32_t timeout, bool buffered, bool time_format_iso_8601, - std::string hostname) + const std::string& hostname) { m_formats.reset(new falco_formats(engine, json_include_output_property, json_include_tags_property)); @@ -271,7 +271,7 @@ inline void falco_outputs::push(const ctrl_msg& cmsg) void falco_outputs::worker() noexcept { watchdog wd; - wd.start([&](std::string payload) -> void { + wd.start([&](const std::string& payload) -> void { falco_logger::log(LOG_CRIT, "\"" + payload + "\" output timeout, all output channels are blocked\n"); }); diff --git a/userspace/falco/falco_outputs.h b/userspace/falco/falco_outputs.h index 0da2267b..beedc60f 100644 --- a/userspace/falco/falco_outputs.h +++ b/userspace/falco/falco_outputs.h @@ -47,7 +47,7 @@ public: uint32_t timeout, bool buffered, bool time_format_iso_8601, - std::string hostname); + const std::string& hostname); virtual ~falco_outputs(); diff --git a/userspace/falco/grpc_server.cpp b/userspace/falco/grpc_server.cpp index c18b02e1..8cdcb8b5 100644 --- a/userspace/falco/grpc_server.cpp +++ b/userspace/falco/grpc_server.cpp @@ -128,12 +128,12 @@ void falco::grpc::server::thread_process(int thread_index) } void falco::grpc::server::init( - std::string server_addr, + const std::string& server_addr, int threadiness, - std::string private_key, - std::string cert_chain, - std::string root_certs, - std::string log_level) + const std::string& private_key, + const std::string& cert_chain, + const std::string& root_certs, + const std::string& log_level) { m_server_addr = server_addr; m_threadiness = threadiness; diff --git a/userspace/falco/grpc_server.h b/userspace/falco/grpc_server.h index ced4020f..59360d40 100644 --- a/userspace/falco/grpc_server.h +++ b/userspace/falco/grpc_server.h @@ -33,12 +33,12 @@ public: virtual ~server() = default; void init( - std::string server_addr, + const std::string& server_addr, int threadiness, - std::string private_key, - std::string cert_chain, - std::string root_certs, - std::string log_level + const std::string& private_key, + const std::string& cert_chain, + const std::string& root_certs, + const std::string& log_level ); void thread_process(int thread_index); void run(); diff --git a/userspace/falco/outputs.h b/userspace/falco/outputs.h index 6b8e456e..b17064a5 100644 --- a/userspace/falco/outputs.h +++ b/userspace/falco/outputs.h @@ -63,7 +63,7 @@ class abstract_output public: virtual ~abstract_output() {} - void init(config oc, bool buffered, std::string hostname, bool json_output) + void init(const config& oc, bool buffered, const std::string& hostname, bool json_output) { m_oc = oc; m_buffered = buffered;