harec

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

commit b2eca0f6270dbd65d42a340c7802bf66879740f6
parent 6dd923e1ead90cadbb7f82e7e8c3dfb21c6ba443
Author: Ember Sawady <ecs@d2evs.net>
Date:   Mon,  6 Feb 2023 16:34:32 +0000

Actually disallow alloc with object of size 0

Ditto for undefined size

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

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

diff --git a/src/check.c b/src/check.c @@ -365,9 +365,15 @@ check_expr_alloc_init(struct context *ctx, } expr->result = type_store_lookup_pointer(ctx->store, aexpr->loc, objtype, ptrflags); - if (expr->result->size == 0 || expr->result->size == SIZE_UNDEFINED) { + if (expr->alloc.init->result->size == 0) { error(ctx, aexpr->loc, expr, - "Cannot allocate object of zero or undefined size"); + "Cannot allocate object with size 0"); + return; + } + if (expr->alloc.init->result->size == SIZE_UNDEFINED) { + error(ctx, aexpr->loc, expr, + "Cannot allocate object of undefined size"); + return; } } diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -114,4 +114,5 @@ export fn main() void = { 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); assert(rt::compile("let a = [*&0];") as rt::exited != rt::EXIT_SUCCESS); + assert(rt::compile("fn a() *void = alloc(void);") as rt::exited != rt::EXIT_SUCCESS); };