Skip to content

Commit

Permalink
reflect, internal/reflectlite: set capacity when slicing unsafe pointers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mdempsky committed Oct 21, 2019
1 parent 7b58581 commit 9989221
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/internal/reflectlite/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit 9989221

Please sign in to comment.