harec

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

commit 942f4bd9e7ea2623c54ab57b602f9f210a0b1bb4
parent 39a715cc39c7afb8828be728709fea328a5a4096
Author: Ember Sawady <ecs@d2evs.net>
Date:   Mon,  6 Feb 2023 16:34:29 +0000

Disallow deref'ing pointers to types of undefined size

Rather than crashing in gen

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

Diffstat:
Msrc/check.c | 6++++++
Mtests/26-regression.ha | 1+
2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -3112,6 +3112,12 @@ check_expr_unarithm(struct context *ctx, "Cannot dereference nullable pointer type"); return; } + if (type_dealias(operand->result)->pointer.referent->size + == SIZE_UNDEFINED) { + error(ctx, aexpr->unarithm.operand->loc, expr, + "Cannot dereference pointer to type of undefined size"); + return; + } expr->result = type_dealias(operand->result)->pointer.referent; break; } diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -112,4 +112,5 @@ export fn main() void = { assert(rt::compile("type a = struct { b: fn() void };") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("fn a() []int = alloc([]: [*]int, 0);") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("fn a() [1]int = [1]: []int: [1]int;") as rt::exited != rt::EXIT_SUCCESS); + assert(rt::compile("fn a() void = &*&a;") as rt::exited != rt::EXIT_SUCCESS); };