From 77871cc664b3a87e4972c874369e2ade79038d76 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 17 Aug 2017 23:13:57 -0700 Subject: [PATCH] runtime: no need to protect key/value increments against end of bucket MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit After the key and value arrays, we have an overflow pointer. So there's no way a past-the-end key or value pointer could point past the end of the containing bucket. So we don't need this additional protection. Update #21459 Change-Id: I7726140033b06b187f7a7d566b3af8cdcaeab0b0 Reviewed-on: https://go-review.googlesource.com/56772 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Martin Möhrmann Reviewed-by: Josh Bleecher Snyder Reviewed-by: Avelino --- src/runtime/hashmap.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 28ea376cf4..f39fb7d3bf 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -1119,12 +1119,12 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { typedmemmove(t.elem, dst.v, v) } dst.i++ - // If we're at the end of the bucket, don't update k/v, - // to avoid pointers pointing past the end of the bucket. - if dst.i < bucketCnt { - dst.k = add(dst.k, uintptr(t.keysize)) - dst.v = add(dst.v, uintptr(t.valuesize)) - } + // These updates might push these pointers past the end of the + // key or value arrays. That's ok, as we have the overflow pointer + // at the end of the bucket to protect against pointing past the + // end of the bucket. + dst.k = add(dst.k, uintptr(t.keysize)) + dst.v = add(dst.v, uintptr(t.valuesize)) } } // Unlink the overflow buckets & clear key/value to help GC. -- 2.48.1