commit 9d1c38d69547d835f7228651e71e8a7d744c456d
parent 81e2fdacc536dab7ad3c1e1da313b80f5ae935b7
Author: Quentin Carbonneaux <quentin@c9x.me>
Date: Sat, 8 Apr 2017 21:11:33 -0400
fix bug in union size computation
The size of a union is the size of the largest
element aligned with the largest alignment.
For example, the size of the following union is
16, not 13 (as returned before this patch).
union {
char c[13];
int i;
};
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/parse.c b/parse.c
@@ -960,9 +960,9 @@ parseseg(Seg *seg, Typ *ty, int t)
err(", or } expected");
seg[n].type = SEnd;
a = 1 << al;
- sz = (sz + a - 1) & -a;
- if (sz >= ty->size)
- ty->size = sz;
+ if (sz < ty->size)
+ sz = ty->size;
+ ty->size = (sz + a - 1) & -a;
ty->align = al;
}