Skip to content

Commit 17f888c

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent c4f87ed commit 17f888c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/reflect/type.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2775,20 +2775,20 @@ func runtimeStructField(field StructField) structField {
27752775
// containing pointer data. Anything after this offset is scalar data.
27762776
// keep in sync with ../cmd/compile/internal/gc/reflect.go
27772777
func typeptrdata(t *rtype) uintptr {
2778-
if !t.pointers() {
2779-
return 0
2780-
}
27812778
switch t.Kind() {
27822779
case Struct:
27832780
st := (*structType)(unsafe.Pointer(t))
27842781
// find the last field that has pointers.
2785-
field := 0
2782+
field := -1
27862783
for i := range st.fields {
27872784
ft := st.fields[i].typ
27882785
if ft.pointers() {
27892786
field = i
27902787
}
27912788
}
2789+
if field == -1 {
2790+
return 0
2791+
}
27922792
f := st.fields[field]
27932793
return f.offset() + f.typ.ptrdata
27942794

0 commit comments

Comments
 (0)