]> Cypherpunks repositories - gostls13.git/commitdiff
reflect, internal/reflectlite: set capacity when slicing unsafe pointers
authorMatthew Dempsky <mdempsky@google.com>
Fri, 18 Oct 2019 19:03:18 +0000 (12:03 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 21 Oct 2019 23:16:36 +0000 (23:16 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/reflectlite/type.go
src/reflect/type.go

index e90071c67cfef800a23321ea6c00e8301e147adc..49a03ac1e1bedc52f3b2d701509d99be892e8ef9 100644 (file)
@@ -629,7 +629,7 @@ func (t *funcType) in() []*rtype {
        if t.inCount == 0 {
                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 {
@@ -641,7 +641,7 @@ func (t *funcType) out() []*rtype {
        if outCount == 0 {
                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.
index 231b38b898a40035765737527af06c2afc5d6924..e4b0432d4200c3594ebf685574e9db1c751c7f62 100644 (file)
@@ -1008,7 +1008,7 @@ func (t *funcType) in() []*rtype {
        if t.inCount == 0 {
                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 {
@@ -1020,7 +1020,7 @@ func (t *funcType) out() []*rtype {
        if outCount == 0 {
                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.