From: Keith Randall Date: Tue, 26 Mar 2019 02:16:46 +0000 (-0700) Subject: reflect: fix typeptrdata X-Git-Tag: go1.13beta1~901 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=17f888c5a8479b0915f23c4a9a453430f276c53b;p=gostls13.git reflect: fix typeptrdata 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- diff --git a/src/reflect/type.go b/src/reflect/type.go index aeb0edc6d1..10509ac418 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -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