harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 03e62282e5d921a43107ebdf32473629342fa538
parent c99e4b84cbd216ef61842f9c2dc07e698461be12
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Thu, 22 Apr 2021 03:27:05 +0200

check: handle zero-sized struct/tuple fields cleanly

Diffstat:
Msrc/type_store.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -182,7 +182,9 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, field->name = strdup(atype->field.name); field->type = type_store_lookup_atype(store, atype->field.type); - + expect(&atype->field.type->loc, field->type->size, + "Struct field size cannot be zero"); + if (atype->offset) { *ccompat = false; struct expression in, out; @@ -433,6 +435,8 @@ tuple_init_from_atype(struct type_store *store, struct type_tuple *cur = &type->tuple; while (atuple) { cur->type = type_store_lookup_atype(store, atuple->type); + expect(&atuple->type->loc, cur->type->size, + "Type of size zero cannot be a tuple member"); cur->offset = type->size % cur->type->align + type->size; type->size += type->size % cur->type->align + cur->type->size; if (type->align < cur->type->align) {