Skip to content

Commit 9989221

Browse files
committed
reflect, internal/reflectlite: set capacity when slicing unsafe pointers
Follow the idiom for allowing -d=checkptr to recognize and verify correctness. Updates #22218. Updates #34972. Change-Id: Ib6001c6f0e6dc535a36bcfaa1ae48e29e0c737f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/202580 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7b58581 commit 9989221

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/internal/reflectlite/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func (t *funcType) in() []*rtype {
629629
if t.inCount == 0 {
630630
return nil
631631
}
632-
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount]
632+
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount:t.inCount]
633633
}
634634

635635
func (t *funcType) out() []*rtype {
@@ -641,7 +641,7 @@ func (t *funcType) out() []*rtype {
641641
if outCount == 0 {
642642
return nil
643643
}
644-
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount]
644+
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount : t.inCount+outCount]
645645
}
646646

647647
// add returns p+x.

src/reflect/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ func (t *funcType) in() []*rtype {
10081008
if t.inCount == 0 {
10091009
return nil
10101010
}
1011-
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount]
1011+
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount:t.inCount]
10121012
}
10131013

10141014
func (t *funcType) out() []*rtype {
@@ -1020,7 +1020,7 @@ func (t *funcType) out() []*rtype {
10201020
if outCount == 0 {
10211021
return nil
10221022
}
1023-
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount]
1023+
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount : t.inCount+outCount]
10241024
}
10251025

10261026
// add returns p+x.

0 commit comments

Comments
 (0)