From 17f888c5a8479b0915f23c4a9a453430f276c53b Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 25 Mar 2019 19:16:46 -0700 Subject: [PATCH] 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 --- src/reflect/type.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 -- 2.50.0