summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorcremno <[email protected]>2015-05-31 13:30:49 +0200
committercremno <[email protected]>2015-05-31 13:30:49 +0200
commit5cd877be7f875546dcc03d80aeeddd4bbbcffe3d (patch)
treef35d538f78eefda4ed0b418b56a4be8ed9b2c9db /src
parent6a1978c7e1f58d3cda8cca390d65e5f64580b169 (diff)
downloadmruby-5cd877be7f875546dcc03d80aeeddd4bbbcffe3d.tar.gz
mruby-5cd877be7f875546dcc03d80aeeddd4bbbcffe3d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/codegen.c8
1 files changed, 7 insertions, 1 deletions
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;