projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
libhashkit: fix UB on unaligned access
[awesomized/libmemcached]
/
libhashkit
/
murmur3.cc
diff --git
a/libhashkit/murmur3.cc
b/libhashkit/murmur3.cc
index 6e2f8ed8db6c773d95d0cd17f2a5fb86a923530c..8d86cfd859cca7e11d6afa72055572d75d6965e5 100644
(file)
--- a/
libhashkit/murmur3.cc
+++ b/
libhashkit/murmur3.cc
@@
-39,7
+39,13
@@
static FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here
-#define getblock(p, i) (p[i])
+#include <cstring>
+template <typename T>
+static inline T getblock(const T *blocks, int i) {
+ T b;
+ memcpy(&b, ((const uint8_t *) blocks) + i * sizeof(T), sizeof(T));
+ return b;
+}
//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche
//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche