murmurhash32 ubsan fix.

This commit is contained in:
Amos Bird 2019-10-19 03:25:20 +08:00
parent 1b8cb59e4b
commit ecebbbf5a6
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
2 changed files with 8 additions and 3 deletions

View File

@ -13,6 +13,7 @@
// machines.
#include "murmurhash2.h"
#include <cstring>
// Platform-specific functions and macros
// Microsoft Visual Studio
@ -48,7 +49,8 @@ uint32_t MurmurHash2(const void * key, int len, uint32_t seed)
while (len >= 4)
{
uint32_t k = *reinterpret_cast<const uint32_t *>(data);
uint32_t k;
memcpy(&k, data, sizeof(k));
k *= m;
k ^= k >> r;
k *= m;
@ -418,4 +420,4 @@ uint32_t MurmurHashAligned2(const void * key, int len, uint32_t seed)
return h;
}
}
}

View File

@ -7,6 +7,7 @@
// non-native version will be less than optimal.
#include "murmurhash3.h"
#include <cstring>
//-----------------------------------------------------------------------------
// Platform-specific functions and macros
@ -53,7 +54,9 @@ inline uint64_t rotl64 ( uint64_t x, int8_t r )
FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i )
{
return p[i];
uint32_t res;
memcpy(&res, p + i, sizeof(res));
return res;
}
FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, int i )