Fix a few compiler warnings from MSVC

This commit is contained in:
Tim Wojtulewicz 2022-10-28 15:50:43 -07:00 committed by Tomer Lev
parent 6bf469b7a8
commit 2e457eb3ea
6 changed files with 20 additions and 21 deletions

View file

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

View file

@ -62,7 +62,7 @@ bool IPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
return false;
}
ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false, len);
ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false, static_cast<int>(len));
packet->l3_proto = L3_IPV6;
}
else

View file

@ -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<int>(affinity_val->AsInt());
const auto& bare_mode_val = node->GetField("bare_mode");

View file

@ -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<const char*>(ptr);
size_t mask = size - 1; // Assume size is a power of 2.
unsigned long l_ptr = reinterpret_cast<unsigned long>(ptr);
unsigned long offset = l_ptr & mask;
intptr_t l_ptr = reinterpret_cast<intptr_t>(ptr);
ptrdiff_t offset = l_ptr & mask;
if ( offset > 0 )
return reinterpret_cast<const void*>(buf - offset + size);
@ -2322,7 +2322,7 @@ void* memory_align_and_pad(void* ptr, size_t size)
char* buf = reinterpret_cast<char*>(ptr);
size_t mask = size - 1;
while ( (reinterpret_cast<unsigned long>(buf) & mask) != 0 )
while ( (reinterpret_cast<intptr_t>(buf) & mask) != 0 )
// Not aligned - zero pad.
*buf++ = '\0';

View file

@ -331,7 +331,7 @@ std::vector<std::string>* tokenize_string(std::string_view input, std::string_vi
std::vector<std::string_view> 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);

View file

@ -271,20 +271,19 @@ extern const char* ZEEK_VERSION_FUNCTION();
#endif
#endif
// FreeBSD doesn't support LeakSanitizer
#if defined(ZEEK_ASAN) && !defined(__FreeBSD__)
#include <sanitizer/lsan_interface.h>
#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
#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'