harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit d53bd3b6c96effd10dcd4728eb01bda898103c73
parent 53ebfbed6c3482be202bc7665d33d9b9c871bcce
Author: Ember Sawady <ecs@d2evs.net>
Date:   Mon,  6 Feb 2023 16:34:26 +0000

Don't crash on struct fields of undefined alignment

Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Msrc/type_store.c | 6+++++-
Mtests/26-regression.ha | 1+
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -187,7 +187,11 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, "Type of undefined size is not a valid struct/union member"); return NULL; } - assert(dim.align != ALIGN_UNDEFINED); + if (dim.align == ALIGN_UNDEFINED) { + error(store->check_context, afield->type->loc, + "Type of undefined alignment is not a valid struct/union member"); + return NULL; + } assert(dim.align != 0); if (afield->offset) { diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -109,4 +109,5 @@ export fn main() void = { fn a() void = A = 0;" ) as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("def A = x && true;") as rt::exited != rt::EXIT_SUCCESS); + assert(rt::compile("type a = struct { b: fn() void };") as rt::exited != rt::EXIT_SUCCESS); };