Merge pull request #7388 from amosbird/ubunaligned

murmurhash32 ubsan fix.
This commit is contained in:
alexey-milovidov 2019-10-19 06:21:20 +03:00 committed by GitHub
commit 2a9e2ab45c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 )