]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix StructOf GC programs
authorKeith Randall <khr@google.com>
Wed, 6 Mar 2019 18:39:08 +0000 (10:39 -0800)
committerKeith Randall <khr@golang.org>
Wed, 6 Mar 2019 20:22:14 +0000 (20:22 +0000)
They are missing a stop byte at the end.

Normally this doesn't matter, but when including a GC program
in another GC program, we strip the last byte. If that last byte
wasn't a stop byte, then we've thrown away part of the program
we actually need.

Fixes #30606

Change-Id: Ie9604beeb84f7f9442e77d31fe64c374ca132cce
Reviewed-on: https://go-review.googlesource.com/c/go/+/165857
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/reflect/type.go
test/fixedbugs/issue30606.go [new file with mode: 0644]

index 5ce80c61dcfdf6de39082c2edd0f63019631293f..531417ea9314d0421e774cf85eb100a449272a0e 100644 (file)
@@ -2712,6 +2712,7 @@ func StructOf(fields []StructField) Type {
                                }
                        }
                }
+               prog = append(prog, 0)
                *(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4)
                typ.kind |= kindGCProg
                typ.gcdata = &prog[0]
diff --git a/test/fixedbugs/issue30606.go b/test/fixedbugs/issue30606.go
new file mode 100644 (file)
index 0000000..bc31982
--- /dev/null
@@ -0,0 +1,20 @@
+// run
+
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "reflect"
+
+func main() {}
+
+func typ(x interface{}) reflect.Type { return reflect.ValueOf(x).Type() }
+
+var x = reflect.New(reflect.StructOf([]reflect.StructField{
+       {Name: "F5", Type: reflect.StructOf([]reflect.StructField{
+               {Name: "F4", Type: reflect.ArrayOf(5462,
+                       reflect.SliceOf(typ(uint64(0))))},
+       })},
+}))