mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: fix size of StructOf ending in zero-sized field
Update #9401. Fixes #18016. Change-Id: Icc24dd10dab1ad8e5cf295e0727d437afa5025c0 Reviewed-on: https://go-review.googlesource.com/33475 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
e12f6ee0ab
commit
50c4dbced9
2 changed files with 46 additions and 0 deletions
|
|
@ -2400,6 +2400,7 @@ func StructOf(fields []StructField) Type {
|
|||
hasGCProg = false // records whether a struct-field type has a GCProg
|
||||
)
|
||||
|
||||
lastzero := uintptr(0)
|
||||
repr = append(repr, "struct {"...)
|
||||
for i, field := range fields {
|
||||
if field.Type == nil {
|
||||
|
|
@ -2570,9 +2571,22 @@ func StructOf(fields []StructField) Type {
|
|||
}
|
||||
size = f.offset + ft.size
|
||||
|
||||
if ft.size == 0 {
|
||||
lastzero = size
|
||||
}
|
||||
|
||||
fs[i] = f
|
||||
}
|
||||
|
||||
if size > 0 && lastzero == size {
|
||||
// This is a non-zero sized struct that ends in a
|
||||
// zero-sized field. We add an extra byte of padding,
|
||||
// to ensure that taking the address of the final
|
||||
// zero-sized field can't manufacture a poitner to the
|
||||
// next object in the heap. See issue 9401.
|
||||
size++
|
||||
}
|
||||
|
||||
var typ *structType
|
||||
var ut *uncommonType
|
||||
var typPin interface {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue