]> git.meshlink.io Git - meshlink/commitdiff
Fix hash functions for keys whose size is not divisible by 4.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 9 Oct 2012 15:49:09 +0000 (17:49 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 9 Oct 2012 15:49:09 +0000 (17:49 +0200)
src/hash.c

index e5f2e0076d74153644ce7618a3ed465d7ef97c6d..cf5ba90a08e13e5dec7ef4e6bf23d7e2347b749b 100644 (file)
 static uint32_t hash_function(const void *p, size_t len) {
        const uint8_t *q = p;
        uint32_t hash = 0;
-       while(len > 0) {
+       while(true) {
                for(int i = len > 4 ? 4 : len; --i;)
                        hash += q[i] << (8 * i);
                hash *= 0x9e370001UL; // Golden ratio prime.
+               if(len <= 4)
+                       break;
                len -= 4;
        }
        return hash;