aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-06-24 19:47:50 -0400
committerRuss Cox <rsc@golang.org>2012-06-24 19:47:50 -0400
commitbca01cd0bfdb9bfda3f076697bda4fae27d4e768 (patch)
tree78f5379af871823f3a45f04933561d0877853111 /src/pkg/runtime
parent35c3afdb62809e40422b5590d807418697ba8660 (diff)
downloadgo-bca01cd0bfdb9bfda3f076697bda4fae27d4e768.tar.xz
runtime: detect hash map collision problems
This can only happen if the hash function we're using is getting far more than it's fair share of collisions, but that has happened to us repeatedly as we've expanded the allowed use cases for hash tables (issue 1544, issue 2609, issue 2630, issue 2883, issue 3695). Maybe this will help the next time we try something new. R=golang-dev, r CC=golang-dev https://golang.org/cl/6306083
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/hashmap.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c
index ea9887a19f..e8965a68d5 100644
--- a/src/pkg/runtime/hashmap.c
+++ b/src/pkg/runtime/hashmap.c
@@ -416,8 +416,12 @@ hash_insert_internal (MapType *t, struct hash_subtable **pst, int32 flags, hash_
*pres = ins_e->data;
return (1);
}
- assert (e_hash != hash || (flags & HASH_REHASH) == 0);
- hash += (e_hash == hash); /* adjust hash if it collides */
+ if (e_hash == hash) { /* adjust hash if it collides */
+ assert ((flags & HASH_REHASH) == 0);
+ hash++;
+ if ((hash & HASH_MASK) == HASH_SUBHASH)
+ runtime·throw("runtime: map hash collision overflow");
+ }
ins_e = HASH_OFFSET (ins_e, elemsize);
ins_i++;
if (e_hash <= hash) { /* set e to insertion point */