]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
contrib/murmurhash3: fix occasional undefined behavior
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 6 Apr 2021 16:01:58 +0000 (18:01 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 14 Apr 2021 14:04:17 +0000 (16:04 +0200)
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*

contrib/murmurhash3/murmurhash3.c

index 995c2366e3114312f37931aa63a337b68cfe735e..373c6cedc65b716d2eccc8704c2bd399c0cae4a1 100644 (file)
@@ -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);