diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2020-06-13 08:41:22 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2020-06-13 08:41:22 -0700 |
commit | 23ca940487565e1216e045b152b44264f9387024 (patch) | |
tree | c92a7d0d2aaa217c29e60f80f021353c9a0b5769 | |
parent | a196b9b7e924d33c465c3ab6a4f7654f36c33284 (diff) | |
download | pugixml-23ca940487565e1216e045b152b44264f9387024.zip pugixml-23ca940487565e1216e045b152b44264f9387024.tar.gz pugixml-23ca940487565e1216e045b152b44264f9387024.tar.bz2 |
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.
-rw-r--r-- | src/pugixml.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
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<unsigned int>(reinterpret_cast<uintptr_t>(key)); + unsigned int h = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(key) & 0xffffffff); // MurmurHash3 32-bit finalizer h ^= h >> 16; |