]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: set alignment to 1 for unions and classes; avoids crash from divide-by-zero
authorRob Pike <r@golang.org>
Fri, 21 Sep 2012 21:25:41 +0000 (07:25 +1000)
committerRob Pike <r@golang.org>
Fri, 21 Sep 2012 21:25:41 +0000 (07:25 +1000)
Fixes #4114.

R=golang-dev, iant, rsc, iant, devon.odell
CC=golang-dev
https://golang.org/cl/6553050

src/cmd/cgo/gcc.go

index d16d0202f663e053ae14a3f952e625311295ce82..eee7602307c77f45614121738358808a3e62ad19 100644 (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)