diff options
author | Matt Broadstone <mbroadst@mongodb.com> | 2022-01-04 16:05:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-05 15:08:17 +0000 |
commit | 46ebb678146598ce3ae12ae401732708e2e3cf01 (patch) | |
tree | f471e01455f76cc6ca124a14b4516e221ed0bab8 /src/third_party/murmurhash3 | |
parent | 7113c62a1ad13a752571ae5842b6826ab504fead (diff) | |
download | mongo-46ebb678146598ce3ae12ae401732708e2e3cf01.tar.gz |
SERVER-62333 use std::ptrdiff_t to avoid UB in MurmurHash3
Diffstat (limited to 'src/third_party/murmurhash3')
-rw-r--r-- | src/third_party/murmurhash3/MurmurHash3.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/third_party/murmurhash3/MurmurHash3.cpp b/src/third_party/murmurhash3/MurmurHash3.cpp index b877baf52a3..5250e81268d 100644 --- a/src/third_party/murmurhash3/MurmurHash3.cpp +++ b/src/third_party/murmurhash3/MurmurHash3.cpp @@ -83,6 +83,8 @@ FORCE_INLINE T nativeToLittle( T t ) return t; } +template <typename T> constexpr std::ptrdiff_t ssizeof = sizeof(T); + //----------------------------------------------------------------------------- // Block read - if your platform needs to do endian-swapping or can only // handle aligned reads, do the conversion here @@ -90,7 +92,7 @@ template <typename T> FORCE_INLINE T getblock( const void* p, int i ) { T t; - std::memcpy(&t, static_cast<const char*>(p) + i * sizeof(T), sizeof(T)); + std::memcpy(&t, static_cast<const char*>(p) + i * ssizeof<T>, sizeof(T)); return nativeToLittle(t); } @@ -109,7 +111,7 @@ template <typename T> FORCE_INLINE void putblock( void* p, int i, T t ) { t = nativeToLittle(t); - std::memcpy(static_cast<char*>(p) + i * sizeof(T), &t, sizeof(T)); + std::memcpy(static_cast<char*>(p) + i * ssizeof<T>, &t, sizeof(T)); } //----------------------------------------------------------------------------- |