summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-07-18 03:53:50 -0700
committerOri Bernstein <ori@markovcorp.com>2017-07-18 10:49:14 -0700
commitd66406270f0743f0713c35cdcc8f371b58a50004 (patch)
tree7b3cf263b994ade7a77378c6bb4a8ac995896262
parentaa40abd25de6fc94621a41b360b5808b3aa57b55 (diff)
downloadmc-d66406270f0743f0713c35cdcc8f371b58a50004.tar.gz
Fix murmurhash2 when string length is a multiple of a 4
The first h *= m after the loop should only happen for len % 4 != 0.
-rw-r--r--lib/std/hashfuncs.myr8
-rw-r--r--util/htab.c6
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index 565ddcc..3046377 100644
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -121,17 +121,19 @@ const murmurhash2 = {data, seed
match data.len
| 3:
h ^= (data[2] : uint32) << 16
- h ^= (data[1] : uint32) <<8
+ h ^= (data[1] : uint32) << 8
h ^= (data[0] : uint32)
+ h *= m
| 2:
- h ^= (data[1] : uint32) <<8
+ h ^= (data[1] : uint32) << 8
h ^= (data[0] : uint32)
+ h *= m
| 1:
h ^= (data[0] : uint32)
+ h *= m
| 0: /* nothing */
| _: die("0 < len < 4 must be true")
;;
- h *= m
h ^= h >> 13
h *= m
diff --git a/util/htab.c b/util/htab.c
index 7ba6291..eafb663 100644
--- a/util/htab.c
+++ b/util/htab.c
@@ -322,10 +322,8 @@ murmurhash2 (void *ptr, size_t len)
case 3: h ^= p[2] << 16;
case 2: h ^= p[1] << 8;
case 1: h ^= p[0] << 0;
- default:
- break;
- };
- h *= m;
+ h *= m;
+ }
h ^= h >> 13;
h *= m;