fix: avoid unaligned pointer dereference (#12318)
This PR avoids undefined behavior in `String.Slice.hash` on unaligned substrings. This could produce a SIGILL on some Arm platforms. Closes #12317
This commit is contained in:
parent
c4d85b7622
commit
c5d2796069
1 changed files with 6 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include <cstring>
|
||||
#include "runtime/hash.h"
|
||||
|
||||
namespace lean {
|
||||
|
|
@ -17,11 +18,13 @@ static uint64 MurmurHash64A(void const * key, size_t len, uint64 seed) {
|
|||
|
||||
uint64 h = seed ^ (len * m);
|
||||
|
||||
const uint64 * data = (const uint64 *)key;
|
||||
const uint64 * end = data + (len/8);
|
||||
const unsigned char * data = reinterpret_cast<const unsigned char *>(key);
|
||||
const unsigned char * end = data + (len/8)*8;
|
||||
|
||||
while (data != end) {
|
||||
uint64 k = *data++;
|
||||
uint64 k;
|
||||
memcpy(&k, data, 8);
|
||||
data += 8;
|
||||
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue