diff options
| author | Peter Pentchev <roam@ringlet.net> | 2022-06-24 20:01:25 +0300 |
|---|---|---|
| committer | Peter Pentchev <roam@ringlet.net> | 2022-06-24 20:01:25 +0300 |
| commit | 085973a486d2a394385e5c3575ca8c2f9c3cc99b (patch) | |
| tree | 87772d1e707df4194c4fc9963bdf2e462ddf07dd /src/hash.cc | |
| parent | 6565f6edd700a1490c670f4e60cd52f7f78dbbe5 (diff) | |
Fix murmurhash for big-endian architectures.
The murmurhash implementation tries to read a sequence of four bytes as
a single little-endian uint32 value. This does not work on e.g. Linux/s390x;
https://buildd.debian.org/status/fetch.php?pkg=kakoune&arch=s390x&ver=2021.11.08-1&stamp=1645975425&raw=0
Diffstat (limited to 'src/hash.cc')
| -rw-r--r-- | src/hash.cc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/hash.cc b/src/hash.cc index ecfd6e46..a603e48b 100644 --- a/src/hash.cc +++ b/src/hash.cc @@ -41,7 +41,11 @@ size_t hash_data(const char* input, size_t len) for (ptrdiff_t i = -nblocks; i; ++i) { uint32_t key; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ memcpy(&key, blocks + 4*i, 4); +#else + key = blocks[4*i] + (blocks[4*i + 1] << 8) + (blocks[4*i + 2] << 16) + (blocks[4*i + 3] << 24); +#endif key *= c1; key = rotl(key, 15); key *= c2; |
