]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: mapassign_* should use typedmemmove to update keys
authorKeith Randall <khr@golang.org>
Sat, 5 Aug 2017 16:58:41 +0000 (09:58 -0700)
committerKeith Randall <khr@golang.org>
Mon, 7 Aug 2017 06:24:42 +0000 (06:24 +0000)
We need to make sure that when the key contains a pointer, we use
a write barrier to update the key.

Also mapdelete_* should use typedmemclr.

Fixes #21297

Change-Id: I63dc90bec1cb909c2c6e08676c9ec853d736cdf8
Reviewed-on: https://go-review.googlesource.com/53414
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/hashmap_fast.go

index 1f9b313219c52c6a31696c2970219cb155d2ca44..67b978790989b05a3c262afc04bba7263d5e786f 100644 (file)
@@ -495,7 +495,7 @@ again:
        }
 
        // store new key/value at insert position
-       *((*uint32)(insertk)) = key
+       typedmemmove(t.key, insertk, unsafe.Pointer(&key))
        *inserti = top
        h.count++
 
@@ -583,7 +583,7 @@ again:
        }
 
        // store new key/value at insert position
-       *((*uint64)(insertk)) = key
+       typedmemmove(t.key, insertk, unsafe.Pointer(&key))
        *inserti = top
        h.count++
 
@@ -723,7 +723,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) {
                        if key != *k {
                                continue
                        }
-                       *k = 0
+                       typedmemclr(t.key, unsafe.Pointer(k))
                        v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*4 + i*uintptr(t.valuesize))
                        typedmemclr(t.elem, v)
                        b.tophash[i] = empty
@@ -778,7 +778,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) {
                        if key != *k {
                                continue
                        }
-                       *k = 0
+                       typedmemclr(t.key, unsafe.Pointer(k))
                        v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*8 + i*uintptr(t.valuesize))
                        typedmemclr(t.elem, v)
                        b.tophash[i] = empty