From 863684a584bfa5b4beeffb8d2a79e735299c1de7 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 4 Jan 2022 16:05:44 +0000 Subject: SERVER-62333 use std::ptrdiff_t to avoid UB in MurmurHash3 --- src/third_party/murmurhash3/MurmurHash3.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/third_party/murmurhash3/MurmurHash3.cpp b/src/third_party/murmurhash3/MurmurHash3.cpp index 03940090b6d..62a0fbeee9b 100644 --- a/src/third_party/murmurhash3/MurmurHash3.cpp +++ b/src/third_party/murmurhash3/MurmurHash3.cpp @@ -82,6 +82,8 @@ FORCE_INLINE T nativeToLittle( T t ) return t; } +template 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 @@ -89,7 +91,7 @@ template FORCE_INLINE T getblock( const void* p, int i ) { T t; - std::memcpy(&t, static_cast(p) + i * sizeof(T), sizeof(T)); + std::memcpy(&t, static_cast(p) + i * ssizeof, sizeof(T)); return nativeToLittle(t); } @@ -108,7 +110,7 @@ template FORCE_INLINE void putblock( void* p, int i, T t ) { t = nativeToLittle(t); - std::memcpy(static_cast(p) + i * sizeof(T), &t, sizeof(T)); + std::memcpy(static_cast(p) + i * ssizeof, &t, sizeof(T)); } //----------------------------------------------------------------------------- -- cgit v1.2.1