]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix typeptrdata
authorKeith Randall <keithr@alum.mit.edu>
Tue, 26 Mar 2019 02:16:46 +0000 (19:16 -0700)
committerKeith Randall <khr@golang.org>
Tue, 26 Mar 2019 03:33:13 +0000 (03:33 +0000)
We can't use ptrdata inside of typeptrdata, because it won't be
properly initialized until typeptrdata returns.

Fixes #31039

Change-Id: Ib8c89191a7e4cce678a05d351bb6ded81ba23aae
Reviewed-on: https://go-review.googlesource.com/c/go/+/169317
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/reflect/type.go

index aeb0edc6d1c412629598c52ffe5e06d818e914c7..10509ac418373b404c411126b109e944b2a9bb72 100644 (file)
@@ -2775,20 +2775,20 @@ func runtimeStructField(field StructField) structField {
 // containing pointer data. Anything after this offset is scalar data.
 // keep in sync with ../cmd/compile/internal/gc/reflect.go
 func typeptrdata(t *rtype) uintptr {
-       if !t.pointers() {
-               return 0
-       }
        switch t.Kind() {
        case Struct:
                st := (*structType)(unsafe.Pointer(t))
                // find the last field that has pointers.
-               field := 0
+               field := -1
                for i := range st.fields {
                        ft := st.fields[i].typ
                        if ft.pointers() {
                                field = i
                        }
                }
+               if field == -1 {
+                       return 0
+               }
                f := st.fields[field]
                return f.offset() + f.typ.ptrdata