diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-02-02 00:38:13 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-02-02 00:38:13 +0100 |
commit | 21cd3b718a2311671ef283759b6d3723fa9db232 (patch) | |
tree | 379794e8f2cde7b4ceb39f22a0b6d9b97ca66f72 /libihash | |
parent | 0cc80b3913489e74f6d5a0ac9b8a4c5523d9cecd (diff) | |
download | hurd-21cd3b718a2311671ef283759b6d3723fa9db232.tar.gz hurd-21cd3b718a2311671ef283759b6d3723fa9db232.tar.bz2 hurd-21cd3b718a2311671ef283759b6d3723fa9db232.zip |
Avoid unaligned memory accesses
Diffstat (limited to 'libihash')
-rw-r--r-- | libihash/murmur3.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/libihash/murmur3.c b/libihash/murmur3.c index e45180a4..891470e4 100644 --- a/libihash/murmur3.c +++ b/libihash/murmur3.c @@ -19,9 +19,9 @@ static inline uint32_t rotl32 ( uint32_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. */ -FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i ) +FORCE_INLINE uint32_t getblock32 ( const uint8_t * p, int i ) { - return p[i]; + return p[i] + (p[i+1]<<8) + (p[i+2]<<16) + (((uint32_t) p[i+3])<<24); } /* Finalization mix - force all bits of a hash block to avalanche. */ @@ -51,11 +51,11 @@ MurmurHash3_x86_32 (const void *key, size_t len, uint32_t seed) /* body */ - const uint32_t * blocks = (const uint32_t *)(data + nblocks*4); + const uint8_t * tail = data + nblocks*4; for(int i = -nblocks; i; i++) { - uint32_t k1 = getblock32(blocks,i); + uint32_t k1 = getblock32(tail,i*4); k1 *= c1; k1 = ROTL32(k1,15); @@ -68,8 +68,6 @@ MurmurHash3_x86_32 (const void *key, size_t len, uint32_t seed) /* tail */ - const uint8_t * tail = (const uint8_t*)(data + nblocks*4); - uint32_t k1 = 0; switch(len & 3) |