Skip to content

Commit

Permalink
build: Fix Clang warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Aponte <[email protected]>
  • Loading branch information
federico-sysdig authored and poiana committed Dec 11, 2023
1 parent 6509c8e commit 5cf1b22
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 67 deletions.
8 changes: 4 additions & 4 deletions userspace/libsinsp/events/sinsp_events_ppm_sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ static inline libsinsp::events::set<ppm_sc_code> 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)
{
throw sinsp_exception("'sc_vec' or 'ev_vec' is unexpected NULL vector!");
}

libsinsp::events::set<ppm_sc_code> sc_set;

for(int sc = 0; sc < PPM_SC_MAX; sc++)
{
if(sc_vec[sc])
Expand Down Expand Up @@ -270,7 +270,7 @@ libsinsp::events::set<ppm_sc_code> 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<int>(ppm_sc) != -1)
{
ppm_sc_set.insert(ppm_sc);
}
Expand Down Expand Up @@ -343,7 +343,7 @@ std::unordered_set<std::string> 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);
}

Expand Down
7 changes: 4 additions & 3 deletions userspace/libsinsp/ifinfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ limitations under the License.
*/

#include <gtest.h>
#define VISIBILITY_PRIVATE
#include "sinsp.h"
#include "sinsp_int.h"
#include "ifinfo.h"

#include <gtest/gtest.h>


uint32_t parse_ipv4_addr(const char *dotted_notation)
{
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class sinsp_plugin
const std::string& path,
const std::shared_ptr<libsinsp::state::table_registry>& 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.
Expand All @@ -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<sinsp_plugin> plugin);
Expand Down Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions userspace/libsinsp/plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -174,13 +173,13 @@ class sinsp_plugin_manager
* This is a reference to the inspector one!
*/
std::vector<std::string>& m_event_sources;

/* vector containing all loaded plugins, added in order of arrival */
std::vector<std::shared_ptr<sinsp_plugin>> m_plugins;

/* The key is the plugin id the value is the index of the plugin in the `m_plugins` vector */
std::unordered_map<uint32_t, size_t> 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<uint32_t, size_t> m_plugins_id_source_index;
mutable size_t m_last_id_in;
Expand Down
6 changes: 3 additions & 3 deletions userspace/libsinsp/procinfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ limitations under the License.

#include "sinsp.h"

#include <gtest.h>
#include <gtest/gtest.h>

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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/sinsp_filtercheck_fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ bool sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT std::vector<extract_valu

// Iterate over the list of open file descriptors and add all
// unique file descriptor types to the vector for comparison
auto fd_type_gather = [this, &fd_types, &values](uint64_t, const sinsp_fdinfo_t& fdinfo)
auto fd_type_gather = [&fd_types, &values](uint64_t, const sinsp_fdinfo_t& fdinfo)
{
char* type = fdinfo.get_typestring();

Expand Down
47 changes: 24 additions & 23 deletions userspace/libsinsp/sinsp_syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ limitations under the License.

#define PRI_BUF_SIZE 16

static std::string s_syslog_severity_strings[] =
static const std::string s_syslog_severity_not_available = "<NA>";
static const std::string s_syslog_severity_strings[] =
{
"emerg", "alert", "crit", "err", "warn", "notice", "info", "debug"
};

static std::string s_syslog_facility_strings[] =
static const std::string s_syslog_facility_strings[] =
{
"kern",
"user",
"mail",
"daemon",
"auth",
"syslog",
"lpr",
"news",
"uucp",
"clock",
"authpriv",
"ftp",
"ntp",
"logaudit",
"logalert",
"kern",
"user",
"mail",
"daemon",
"auth",
"syslog",
"lpr",
"news",
"uucp",
"clock",
"authpriv",
"ftp",
"ntp",
"logaudit",
"logalert",
"cron",
"local0",
"local1",
Expand Down Expand Up @@ -72,23 +73,23 @@ void sinsp_syslog_decoder::parse_data(const char *data, uint32_t len)
decode_message(data, len, pri, j);
}

const std::string sinsp_syslog_decoder::get_severity_str() const
const std::string& sinsp_syslog_decoder::get_severity_str() const
{
if(!is_data_valid() || m_severity >= sizeof(s_syslog_severity_strings) / sizeof(s_syslog_severity_strings[0]))
{
return "<NA>";
return s_syslog_severity_not_available;
}
else
{
return s_syslog_severity_strings[m_severity];
}
}

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 "<NA>";
return s_syslog_severity_not_available;
}
else
{
Expand Down Expand Up @@ -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 = "<NA>";
m_infostr = s_syslog_severity_not_available;
}
else
{
Expand Down
17 changes: 4 additions & 13 deletions userspace/libsinsp/sinsp_syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/container_info.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<short, short, std::vector<short>>{3, 500, {125, 250, 500}},
Expand Down
2 changes: 0 additions & 2 deletions userspace/libsinsp/test/plugins/sample_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 3 additions & 9 deletions userspace/libsinsp/tuples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bool T> class mem_layout_test;
template <> class mem_layout_test<true>{}; // empty struct take 1 byte of mem

static auto check_size = mem_layout_test<sizeof (ipv6addr) == 16>();
// is_pod check split into is_standard_layout && is_trivial to be C++20 future proof
static auto check_layout = mem_layout_test<std::is_standard_layout<ipv6addr>::value && std::is_trivial<ipv6addr>::value>();
// end layout checks
static_assert(std::is_standard_layout<ipv6addr>::value && std::is_trivial<ipv6addr>::value);

ipv6addr ipv6addr::empty_address ("0::");//= {0x00000000, 0x00000000, 0x00000000, 0x00000000};

Expand Down

0 comments on commit 5cf1b22

Please sign in to comment.