update(userspace): solve cppcheck performance suggestions

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2022-10-12 08:51:47 +00:00 committed by poiana
parent 5e531870a9
commit 3629c4dc4a
9 changed files with 28 additions and 28 deletions

View File

@ -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)
{
}

View File

@ -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<falco_source>& 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;

View File

@ -51,7 +51,7 @@ falco_configuration::~falco_configuration()
}
}
void falco_configuration::init(string conf_filename, const vector<string> &cmdline_options)
void falco_configuration::init(const string& conf_filename, const vector<string> &cmdline_options)
{
string m_config_file = conf_filename;
m_config = new yaml_configuration();

View File

@ -216,7 +216,7 @@ public:
falco_configuration();
virtual ~falco_configuration();
void init(std::string conf_filename, const std::vector<std::string>& cmdline_options);
void init(const std::string& conf_filename, const std::vector<std::string>& cmdline_options);
void init(const std::vector<std::string>& cmdline_options);
static void read_rules_file_directory(const string& path, list<string>& rules_filenames, list<string> &rules_folders);

View File

@ -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<std::string> 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");
});

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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;