1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:08:37 -07:00

cgo: set alignment to 1 for unions and classes; avoids crash from divide-by-zero

Fixes #4114.

R=golang-dev, iant, rsc, iant, devon.odell
CC=golang-dev
https://golang.org/cl/6553050
This commit is contained in:
Rob Pike 2012-09-22 07:25:41 +10:00
parent 3730ddcbd8
commit f934bb8eba

View File

@ -1190,11 +1190,12 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
t.Go = name // publish before recursive calls
goIdent[name.Name] = name
switch dt.Kind {
case "union", "class":
case "class", "union":
t.Go = c.Opaque(t.Size)
if t.C.Empty() {
t.C.Set("typeof(unsigned char[%d])", t.Size)
}
t.Align = 1 // TODO: should probably base this on field alignment.
typedef[name.Name] = t
case "struct":
g, csyntax, align := c.Struct(dt, pos)