Commit 9989221a authored by Matthew Dempsky's avatar Matthew Dempsky

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 <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7b58581a
...@@ -629,7 +629,7 @@ func (t *funcType) in() []*rtype { ...@@ -629,7 +629,7 @@ func (t *funcType) in() []*rtype {
if t.inCount == 0 { if t.inCount == 0 {
return nil return nil
} }
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount] return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount:t.inCount]
} }
func (t *funcType) out() []*rtype { func (t *funcType) out() []*rtype {
...@@ -641,7 +641,7 @@ func (t *funcType) out() []*rtype { ...@@ -641,7 +641,7 @@ func (t *funcType) out() []*rtype {
if outCount == 0 { if outCount == 0 {
return nil return nil
} }
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount] return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount : t.inCount+outCount]
} }
// add returns p+x. // add returns p+x.
......
...@@ -1008,7 +1008,7 @@ func (t *funcType) in() []*rtype { ...@@ -1008,7 +1008,7 @@ func (t *funcType) in() []*rtype {
if t.inCount == 0 { if t.inCount == 0 {
return nil return nil
} }
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount] return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "t.inCount > 0"))[:t.inCount:t.inCount]
} }
func (t *funcType) out() []*rtype { func (t *funcType) out() []*rtype {
...@@ -1020,7 +1020,7 @@ func (t *funcType) out() []*rtype { ...@@ -1020,7 +1020,7 @@ func (t *funcType) out() []*rtype {
if outCount == 0 { if outCount == 0 {
return nil return nil
} }
return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount] return (*[1 << 20]*rtype)(add(unsafe.Pointer(t), uadd, "outCount > 0"))[t.inCount : t.inCount+outCount : t.inCount+outCount]
} }
// add returns p+x. // add returns p+x.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment