From 2e457eb3eae4aad1f0f4d77e84a3bc2b5bdb2c52 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 28 Oct 2022 15:50:43 -0700 Subject: [PATCH] Fix a few compiler warnings from MSVC --- src/ScriptProfile.cc | 2 +- src/packet_analysis/protocol/ip/IP.cc | 2 +- src/supervisor/Supervisor.cc | 2 +- src/util.cc | 10 +++++----- src/util.h | 2 +- zeek-config.h.in | 23 +++++++++++------------ 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/ScriptProfile.cc b/src/ScriptProfile.cc index 862b4c5ebe..22f09dfb63 100644 --- a/src/ScriptProfile.cc +++ b/src/ScriptProfile.cc @@ -102,7 +102,7 @@ ScriptProfileMgr::~ScriptProfileMgr() auto& fp = fs.second; auto n = func->GetBodies().size(); if ( n > 1 ) - fprintf(f, "%s\t%lu-locations\t%s\t%d\t%.06f\t%0.6f\t%" PRIu64 "\t%lld\n", + fprintf(f, "%s\t%zu-locations\t%s\t%d\t%.06f\t%0.6f\t%" PRIu64 "\t%lld\n", fp.Name().c_str(), n, func->GetType()->FlavorString().c_str(), fp.NumCalls(), fp.CPUTime(), 0.0, fp.Memory(), 0LL); } diff --git a/src/packet_analysis/protocol/ip/IP.cc b/src/packet_analysis/protocol/ip/IP.cc index 1263317317..19d5908d67 100644 --- a/src/packet_analysis/protocol/ip/IP.cc +++ b/src/packet_analysis/protocol/ip/IP.cc @@ -62,7 +62,7 @@ bool IPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet) return false; } - ip_hdr = std::make_shared((const struct ip6_hdr*)data, false, len); + ip_hdr = std::make_shared((const struct ip6_hdr*)data, false, static_cast(len)); packet->l3_proto = L3_IPV6; } else diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index a2dc6a66ba..8d7fc4f3ab 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1249,7 +1249,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) const auto& affinity_val = node->GetField("cpu_affinity"); if ( affinity_val ) - rval.cpu_affinity = affinity_val->AsInt(); + rval.cpu_affinity = static_cast(affinity_val->AsInt()); const auto& bare_mode_val = node->GetField("bare_mode"); diff --git a/src/util.cc b/src/util.cc index bdf4cc452a..79da74bf9f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1128,9 +1128,9 @@ TEST_CASE("util streq") CHECK(streq("abcd", "efgh") == false); } -int streq(const char* s1, const char* s2) +bool streq(const char* s1, const char* s2) { - return ! strcmp(s1, s2); + return strcmp(s1, s2) == 0; } bool starts_with(std::string_view s, std::string_view beginning) @@ -2282,8 +2282,8 @@ const void* memory_align(const void* ptr, size_t size) const char* buf = reinterpret_cast(ptr); size_t mask = size - 1; // Assume size is a power of 2. - unsigned long l_ptr = reinterpret_cast(ptr); - unsigned long offset = l_ptr & mask; + intptr_t l_ptr = reinterpret_cast(ptr); + ptrdiff_t offset = l_ptr & mask; if ( offset > 0 ) return reinterpret_cast(buf - offset + size); @@ -2322,7 +2322,7 @@ void* memory_align_and_pad(void* ptr, size_t size) char* buf = reinterpret_cast(ptr); size_t mask = size - 1; - while ( (reinterpret_cast(buf) & mask) != 0 ) + while ( (reinterpret_cast(buf) & mask) != 0 ) // Not aligned - zero pad. *buf++ = '\0'; diff --git a/src/util.h b/src/util.h index 6471b8019a..8919b8276a 100644 --- a/src/util.h +++ b/src/util.h @@ -331,7 +331,7 @@ std::vector* tokenize_string(std::string_view input, std::string_vi std::vector tokenize_string(std::string_view input, const char delim) noexcept; extern char* copy_string(const char* s); -extern int streq(const char* s1, const char* s2); +extern bool streq(const char* s1, const char* s2); extern bool starts_with(std::string_view s, std::string_view beginning); extern bool ends_with(std::string_view s, std::string_view ending); diff --git a/zeek-config.h.in b/zeek-config.h.in index a6492ddd53..f2aa463686 100644 --- a/zeek-config.h.in +++ b/zeek-config.h.in @@ -271,20 +271,19 @@ extern const char* ZEEK_VERSION_FUNCTION(); #endif #endif -// FreeBSD doesn't support LeakSanitizer #if defined(ZEEK_ASAN) && !defined(__FreeBSD__) - #include - #define ZEEK_LSAN_CHECK(x) __lsan_do_leak_check(x) - #define ZEEK_LSAN_ENABLE(x) __lsan_enable(x) - #define ZEEK_LSAN_IGNORE(x) __lsan_ignore_object(x) - #define ZEEK_LSAN_DISABLE(x) __lsan_disable(x) - #define ZEEK_LSAN_DISABLE_SCOPE(x) __lsan::ScopedDisabler x + #include + #define ZEEK_LSAN_CHECK(...) __lsan_do_leak_check(__VA_ARGS__) + #define ZEEK_LSAN_ENABLE(...) __lsan_enable(__VA_ARGS__) + #define ZEEK_LSAN_IGNORE(...) __lsan_ignore_object(__VA_ARGS__) + #define ZEEK_LSAN_DISABLE(...) __lsan_disable(__VA_ARGS__) + #define ZEEK_LSAN_DISABLE_SCOPE(...) __lsan::ScopedDisabler __VA_ARGS__ #else - #define ZEEK_LSAN_CHECK(x) - #define ZEEK_LSAN_ENABLE(x) - #define ZEEK_LSAN_IGNORE(x) - #define ZEEK_LSAN_DISABLE(x) - #define ZEEK_LSAN_DISABLE_SCOPE(x) + #define ZEEK_LSAN_CHECK(...) + #define ZEEK_LSAN_ENABLE(...) + #define ZEEK_LSAN_IGNORE(...) + #define ZEEK_LSAN_DISABLE(...) + #define ZEEK_LSAN_DISABLE_SCOPE(...) #endif // This part is dependent on calling configure with '--sanitizers=thread'