From cec21733815d1897963fdd2b4910c8f885b91289 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 22 Sep 2019 10:32:44 +0300 Subject: [PATCH] array: fix memory bug with mutable array args --- compiler/gen_c.v | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/gen_c.v b/compiler/gen_c.v index 3585fd88d4..c00260218a 100644 --- a/compiler/gen_c.v +++ b/compiler/gen_c.v @@ -461,7 +461,11 @@ fn (p mut Parser) gen_array_push(ph int, typ, expr_type, tmp, tmp_typ string) { // Don't dereference if it's already a mutable array argument (`fn foo(mut []int)`) push_call := if typ.contains('*'){'_PUSH('} else { '_PUSH(&'} p.cgen.set_placeholder(ph, push_call) - p.gen('), $tmp, $tmp_typ)') + if tmp_typ.ends_with('*') { + p.gen('), $tmp, ${tmp_typ.left(tmp_typ.len - 1)})') + } else { + p.gen('), $tmp, $tmp_typ)') + } } }