From 5cf1b22dfdbd2f9055554bc48a584ef36b3beefb Mon Sep 17 00:00:00 2001 From: Federico Aponte Date: Sun, 3 Dec 2023 18:47:47 +0100 Subject: [PATCH] build: Fix Clang warnings Signed-off-by: Federico Aponte --- .../libsinsp/events/sinsp_events_ppm_sc.cpp | 8 ++-- userspace/libsinsp/ifinfo_test.cpp | 7 +-- userspace/libsinsp/plugin.h | 6 +-- userspace/libsinsp/plugin_manager.h | 7 ++- userspace/libsinsp/procinfo_test.cpp | 6 +-- userspace/libsinsp/sinsp_filtercheck_fd.cpp | 2 +- userspace/libsinsp/sinsp_syslog.cpp | 47 ++++++++++--------- userspace/libsinsp/sinsp_syslog.h | 17 ++----- userspace/libsinsp/test/container_info.ut.cpp | 2 +- .../libsinsp/test/plugins/sample_table.h | 2 - userspace/libsinsp/tuples.cpp | 12 ++--- 11 files changed, 49 insertions(+), 67 deletions(-) diff --git a/userspace/libsinsp/events/sinsp_events_ppm_sc.cpp b/userspace/libsinsp/events/sinsp_events_ppm_sc.cpp index 7f98e5ec9b..e9fa86f4b7 100644 --- a/userspace/libsinsp/events/sinsp_events_ppm_sc.cpp +++ b/userspace/libsinsp/events/sinsp_events_ppm_sc.cpp @@ -159,7 +159,7 @@ static inline libsinsp::events::set get_sc_set_from_cat(const std:: ev_vec[ev] = 1; } } - + /* Obtain all sc associated with those events */ if(scap_get_ppm_sc_from_events(ev_vec.data(), sc_vec.data()) != SCAP_SUCCESS) { @@ -167,7 +167,7 @@ static inline libsinsp::events::set get_sc_set_from_cat(const std:: } libsinsp::events::set sc_set; - + for(int sc = 0; sc < PPM_SC_MAX; sc++) { if(sc_vec[sc]) @@ -270,7 +270,7 @@ libsinsp::events::set libsinsp::events::sc_names_to_sc_set(const st for (const auto &name : syscalls) { auto ppm_sc = scap_ppm_sc_from_name(name.c_str()); - if(ppm_sc != -1) + if(static_cast(ppm_sc) != -1) { ppm_sc_set.insert(ppm_sc); } @@ -343,7 +343,7 @@ std::unordered_set libsinsp::events::sc_set_to_event_names(const li // event code mapping. This is only expected to happen for generic events. auto remaining_sc_set = ppm_sc_set.diff(event_set_to_sc_set(event_set)); auto remaining_sc_names_set = sc_set_to_sc_names(remaining_sc_set); - + return unordered_set_union(event_names_set, remaining_sc_names_set); } diff --git a/userspace/libsinsp/ifinfo_test.cpp b/userspace/libsinsp/ifinfo_test.cpp index 5bce766254..6dc22a82e8 100644 --- a/userspace/libsinsp/ifinfo_test.cpp +++ b/userspace/libsinsp/ifinfo_test.cpp @@ -16,12 +16,13 @@ limitations under the License. */ -#include #define VISIBILITY_PRIVATE #include "sinsp.h" #include "sinsp_int.h" #include "ifinfo.h" +#include + uint32_t parse_ipv4_addr(const char *dotted_notation) { @@ -58,9 +59,9 @@ sinsp_ipv4_ifinfo make_ipv4_localhost() void convert_to_string(char* dest, size_t len, uint32_t addr) { snprintf( - dest, + dest, len, - "%d.%d.%d.%d", + "%d.%d.%d.%d", (addr & 0xFF), ((addr & 0xFF00) >> 8), ((addr & 0xFF0000) >> 16), diff --git a/userspace/libsinsp/plugin.h b/userspace/libsinsp/plugin.h index c3cf8ad5b1..c77b36a32b 100755 --- a/userspace/libsinsp/plugin.h +++ b/userspace/libsinsp/plugin.h @@ -61,7 +61,7 @@ class sinsp_plugin const std::string& path, const std::shared_ptr& treg, std::string& errstr); - + /** * @brief Create a plugin from the provided api vtable. * On error, the shared_ptr will == nullptr and errstr is set with an error. @@ -79,7 +79,7 @@ class sinsp_plugin /** * @brief If the plugin has CAP_EXTRACTION capability, returns a * filtercheck with its exported fields. Returns NULL otherwise. - * + * * todo(jasondellaluce): make this return a unique_ptr */ static sinsp_filter_check* new_filtercheck(std::shared_ptr plugin); @@ -122,8 +122,6 @@ class sinsp_plugin m_async_event_names(), m_async_evt_handler(nullptr) { } virtual ~sinsp_plugin(); - sinsp_plugin(sinsp_plugin&&) = default; - sinsp_plugin& operator = (sinsp_plugin&&) = default; sinsp_plugin(const sinsp_plugin& s) = delete; sinsp_plugin& operator = (const sinsp_plugin& s) = delete; diff --git a/userspace/libsinsp/plugin_manager.h b/userspace/libsinsp/plugin_manager.h index 73763a98d4..cc21e07a35 100755 --- a/userspace/libsinsp/plugin_manager.h +++ b/userspace/libsinsp/plugin_manager.h @@ -43,7 +43,6 @@ class sinsp_plugin_manager m_last_source_out(-1) { } virtual ~sinsp_plugin_manager() = default; sinsp_plugin_manager(sinsp_plugin_manager&&) = default; - sinsp_plugin_manager& operator = (sinsp_plugin_manager&&) = default; sinsp_plugin_manager(const sinsp_plugin_manager& s) = delete; sinsp_plugin_manager& operator = (const sinsp_plugin_manager& s) = delete; @@ -77,7 +76,7 @@ class sinsp_plugin_manager { // note: we avoid duplicate entries in the evt sources list bool existing = false; - + /* Get the source index: * - First we search it in the array to see if it is already present * - if not present the new source position will be the first available in the `m_event_sources` array @@ -174,13 +173,13 @@ class sinsp_plugin_manager * This is a reference to the inspector one! */ std::vector& m_event_sources; - + /* vector containing all loaded plugins, added in order of arrival */ std::vector> m_plugins; /* The key is the plugin id the value is the index of the plugin in the `m_plugins` vector */ std::unordered_map m_plugins_id_index; - + /* The key is the plugin id the value is the index of the plugin source in the `m_event_sources` vector */ std::unordered_map m_plugins_id_source_index; mutable size_t m_last_id_in; diff --git a/userspace/libsinsp/procinfo_test.cpp b/userspace/libsinsp/procinfo_test.cpp index 4aa1b8ea0d..e9ef9eeb3d 100644 --- a/userspace/libsinsp/procinfo_test.cpp +++ b/userspace/libsinsp/procinfo_test.cpp @@ -18,14 +18,14 @@ limitations under the License. #include "sinsp.h" -#include +#include sinsp_procinfo make_procinfo(sinsp* inspector, int64_t tid, int64_t tgid) { sinsp_procinfo procinfo(inspector); procinfo.m_tid = tid; procinfo.m_tgid = tgid; - return procinfo; + return procinfo; } sinsp_procinfo make_procinfo(int64_t tid, int64_t tgid) @@ -105,7 +105,7 @@ TEST(procinfo_multi_thread,add_non_existing_fd) inspector.add_process(parent); inspector.add_process(child); - + EXPECT_TRUE(NULL == inspector.get_process(1)->get_fd(0)); sinsp_fdinfo fdinfo; diff --git a/userspace/libsinsp/sinsp_filtercheck_fd.cpp b/userspace/libsinsp/sinsp_filtercheck_fd.cpp index 70798dcae9..ce4ebe8ef2 100644 --- a/userspace/libsinsp/sinsp_filtercheck_fd.cpp +++ b/userspace/libsinsp/sinsp_filtercheck_fd.cpp @@ -479,7 +479,7 @@ bool sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT std::vector= sizeof(s_syslog_severity_strings) / sizeof(s_syslog_severity_strings[0])) { - return ""; + return s_syslog_severity_not_available; } else { @@ -84,11 +85,11 @@ const std::string sinsp_syslog_decoder::get_severity_str() const } } -const std::string sinsp_syslog_decoder::get_facility_str() const +const std::string& sinsp_syslog_decoder::get_facility_str() const { if(!is_data_valid() || m_facility >= sizeof(s_syslog_facility_strings) / sizeof(s_syslog_facility_strings[0])) { - return ""; + return s_syslog_severity_not_available; } else { @@ -118,11 +119,11 @@ void sinsp_syslog_decoder::decode_message(const char *data, uint32_t len, char* m_msg.assign(data + pristrlen + 2, len - pristrlen - 2); } -const std::string sinsp_syslog_decoder::get_info_line() +const std::string& sinsp_syslog_decoder::get_info_line() { if (!is_data_valid()) { - m_infostr = ""; + m_infostr = s_syslog_severity_not_available; } else { diff --git a/userspace/libsinsp/sinsp_syslog.h b/userspace/libsinsp/sinsp_syslog.h index f6ffd0349a..7e53a582f0 100644 --- a/userspace/libsinsp/sinsp_syslog.h +++ b/userspace/libsinsp/sinsp_syslog.h @@ -27,20 +27,11 @@ limitations under the License. class sinsp_syslog_decoder { public: - sinsp_syslog_decoder() = default; - ~sinsp_syslog_decoder() = default; - sinsp_syslog_decoder(sinsp_syslog_decoder&&) = default; - sinsp_syslog_decoder& operator = (sinsp_syslog_decoder&&) = default; - sinsp_syslog_decoder(const sinsp_syslog_decoder& s) = default; - sinsp_syslog_decoder& operator = (const sinsp_syslog_decoder& s) = default; - void parse_data(const char *data, uint32_t len); - const std::string get_info_line(); - - const std::string get_severity_str() const; - - const std::string get_facility_str() const; + const std::string& get_info_line(); + const std::string& get_severity_str() const; + const std::string& get_facility_str() const; inline void reset() { @@ -67,7 +58,7 @@ class sinsp_syslog_decoder return m_severity; } - inline const std::string get_msg() const + inline const std::string& get_msg() const { return m_msg; } diff --git a/userspace/libsinsp/test/container_info.ut.cpp b/userspace/libsinsp/test/container_info.ut.cpp index b922b64250..24f8337924 100644 --- a/userspace/libsinsp/test/container_info.ut.cpp +++ b/userspace/libsinsp/test/container_info.ut.cpp @@ -59,7 +59,7 @@ TEST_P(sinsp_container_lookup_test, delays_match) } } -INSTANTIATE_TEST_CASE_P(sinsp_container_lookup, +INSTANTIATE_TEST_SUITE_P(sinsp_container_lookup, sinsp_container_lookup_test, ::testing::Values( std::tuple>{3, 500, {125, 250, 500}}, diff --git a/userspace/libsinsp/test/plugins/sample_table.h b/userspace/libsinsp/test/plugins/sample_table.h index 72602f70a7..77873cf58b 100644 --- a/userspace/libsinsp/test/plugins/sample_table.h +++ b/userspace/libsinsp/test/plugins/sample_table.h @@ -60,9 +60,7 @@ class sample_table name(n), lasterr(err), strings(), entries(), fields() { } virtual ~sample_table() = default; sample_table(sample_table&&) = default; - sample_table& operator = (sample_table&&) = default; sample_table(const sample_table& s) = default; - sample_table& operator = (const sample_table& s) = default; static const char* get_name(ss_plugin_table_t* _t) { diff --git a/userspace/libsinsp/tuples.cpp b/userspace/libsinsp/tuples.cpp index 8f56078ff7..f949bb8aea 100644 --- a/userspace/libsinsp/tuples.cpp +++ b/userspace/libsinsp/tuples.cpp @@ -24,17 +24,11 @@ limitations under the License. #include "sinsp_exception.h" #include "logger.h" +// ensure proper memory layout for ipv6addr class during compile time +static_assert(sizeof(ipv6addr) == 16); -/* - * a few line below to enforce proper memory layout for ipv6addr class during compile time - */ -template class mem_layout_test; -template <> class mem_layout_test{}; // empty struct take 1 byte of mem - -static auto check_size = mem_layout_test(); // is_pod check split into is_standard_layout && is_trivial to be C++20 future proof -static auto check_layout = mem_layout_test::value && std::is_trivial::value>(); -// end layout checks +static_assert(std::is_standard_layout::value && std::is_trivial::value); ipv6addr ipv6addr::empty_address ("0::");//= {0x00000000, 0x00000000, 0x00000000, 0x00000000};