From 23ca940487565e1216e045b152b44264f9387024 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 13 Jun 2020 08:41:22 -0700 Subject: [PATCH] Work around a false positive in MSVC debug runtime checker In some MSVC versions on x64 configurations, the hashing function triggers this failure: Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss of data. If this was intentional, you should mask the source of the cast with the appropriate bitmask. This is similar to the integer sanitizer - this code is valid C++ but MSVC decides to warn about this nonetheless. Masking the pointer's low 32 bits fixes the issue. Fixes #357. --- src/pugixml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c3df93b..4d0c2c9 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -378,7 +378,7 @@ PUGI__NS_BEGIN static PUGI__UNSIGNED_OVERFLOW unsigned int hash(const void* key) { - unsigned int h = static_cast(reinterpret_cast(key)); + unsigned int h = static_cast(reinterpret_cast(key) & 0xffffffff); // MurmurHash3 32-bit finalizer h ^= h >> 16;