From: Vladimír Čunát Date: Tue, 6 Apr 2021 16:01:58 +0000 (+0200) Subject: contrib/murmurhash3: fix occasional undefined behavior X-Git-Tag: v5.3.2~10^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1dc3666eab63a4017a9be4f12ad84a839d50cdb0;p=thirdparty%2Fknot-resolver.git contrib/murmurhash3: fix occasional undefined behavior murmurhash3.c:43:40: runtime error: addition of unsigned offset to 0x7ffce41c2014 overflowed to 0x7ffce41c2000 The `i` was used in a super-ugly way; I suspect the only reason was to optimize that end-loop condition was zero comparison *vomit* --- diff --git a/contrib/murmurhash3/murmurhash3.c b/contrib/murmurhash3/murmurhash3.c index 995c2366e..373c6cedc 100644 --- a/contrib/murmurhash3/murmurhash3.c +++ b/contrib/murmurhash3/murmurhash3.c @@ -36,11 +36,10 @@ uint32_t hash(const char* data, size_t len_) //---------- // body - int i; - for(i = -nblocks; i; i++) + for(int i = 0; i < nblocks; ++i) { uint32_t k1; - memcpy(&k1, data + nblocks * 4 + i * sizeof(k1), sizeof(k1)); + memcpy(&k1, data + i * sizeof(k1), sizeof(k1)); k1 *= c1; k1 = rotl32(k1, 15);