cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 1891c1c81b7ed607d75eaaa4fde6d20121941085
parent fca0b26275a82c480a5286c281834dad6887b410
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 15 Apr 2019 01:40:44 -0700

decl: Fix uninitialized access with unnamed bit-fields

Diffstat:
Mdecl.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/decl.c b/decl.c @@ -57,7 +57,7 @@ enum funcspec { struct structbuilder { struct type *type; struct member **last; - int bits; /* number of bits remaining in the last byte */ + unsigned bits; /* number of bits remaining in the last byte */ }; struct decl * @@ -687,13 +687,13 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, ui t->size = end; b->bits = 0; } - if (width) { + if (name) { m->offset = ALIGNDOWN(t->size - !!b->bits, mt.type->size); m->bits.before = (t->size - m->offset) * 8 - b->bits; m->bits.after = mt.type->size * 8 - width - m->bits.before; - t->size += (width - b->bits + 7) / 8; - b->bits = m->bits.after % 8; } + t->size += (width - b->bits + 7) / 8; + b->bits = (b->bits - width) % 8; align = mt.type->align; } if (t->align < align)