1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

array: fix memory bug with mutable array args

This commit is contained in:
Alexander Medvednikov 2019-09-22 10:32:44 +03:00
parent 45e9a8fd66
commit cec2173381

View File

@ -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)`) // Don't dereference if it's already a mutable array argument (`fn foo(mut []int)`)
push_call := if typ.contains('*'){'_PUSH('} else { '_PUSH(&'} push_call := if typ.contains('*'){'_PUSH('} else { '_PUSH(&'}
p.cgen.set_placeholder(ph, push_call) 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)')
}
} }
} }