harec

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

commit 9e471e760cbab04fa0cba30b586dc532cf9b6848
parent 38de3d690073d5d4bac8695b747179097beaa1b7
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Tue,  1 Mar 2022 04:45:10 +0000

eval: fix default value for slices

Minimal reproduction (not sure why g() is necessary in order to get a
symptom out of the heap corruption):

type a = struct {
	b: []int,
};

type d = struct{
	e: [2][]a,
};

let f: d = d { ... };

fn g(h: f64) void = (h * 0.0, 0);

export fn main() void = {
	append(f.e[0], a { ... });
	append(f.e[1], a { ... });
	let a: []int = [];
	append(a, 0);
	append(a, 0);
	append(a, 0);
	assert(a[0] == 0);
};

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

Diffstat:
Msrc/eval.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c @@ -548,6 +548,7 @@ constant_default(struct context *ctx, struct expression *v) case STORAGE_NULL: case STORAGE_RCONST: case STORAGE_RUNE: + case STORAGE_SLICE: case STORAGE_BOOL: break; // calloc does this for us case STORAGE_STRUCT: @@ -563,7 +564,6 @@ constant_default(struct context *ctx, struct expression *v) v->constant.string.len = 0; break; case STORAGE_ARRAY: - case STORAGE_SLICE: v->constant.array = xcalloc(1, sizeof(struct array_constant)); v->constant.array->value = xcalloc(1, sizeof(struct expression)); v->constant.array->value->type = EXPR_CONSTANT;