From 5cd877be7f875546dcc03d80aeeddd4bbbcffe3d Mon Sep 17 00:00:00 2001 From: cremno Date: Sun, 31 May 2015 13:30:49 +0200 Subject: fix masgn nosplat array rhs bug The rest lhs variable has to be an empty array if rhs is an array with less elements than pre + post lhs variables. The codegen generated OP_ARRAY with an invalid length (such as 127 for *a, b = []) because rn was negative. --- src/codegen.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/codegen.c b/src/codegen.c index 6f1f75e88..be630b9a8 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1615,8 +1615,14 @@ codegen(codegen_scope *s, node *tree, int val) } } if (t->car) { /* rest (len - pre - post) */ - int rn = len - post - n; + int rn; + if (len < post + n) { + rn = 0; + } + else { + rn = len - post - n; + } genop(s, MKOP_ABC(OP_ARRAY, cursp(), rhs+n, rn)); gen_assignment(s, t->car, cursp(), NOVAL); n += rn; -- cgit v1.2.3