summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-05-31 18:30:37 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-05-31 18:30:37 +0900
commit6a1978c7e1f58d3cda8cca390d65e5f64580b169 (patch)
treeabe8c03d93bb49ca7613baf96928f0fdd1bff9be
parent9ef4bbb10d827fb41edc8c2984e0b80fcdbea900 (diff)
downloadmruby-6a1978c7e1f58d3cda8cca390d65e5f64580b169.tar.gz
mruby-6a1978c7e1f58d3cda8cca390d65e5f64580b169.zip
fix OP_APOST bug for no pre arg cases; fix #2810
-rw-r--r--src/vm.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/vm.c b/src/vm.c
index dd0d0ba43..1f3b05df2 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2125,33 +2125,28 @@ RETRY_TRY_BLOCK:
int pre = GETARG_B(i);
int post = GETARG_C(i);
+ struct RArray *ary;
+ int len, idx;
+
if (!mrb_array_p(v)) {
- regs[a++] = mrb_ary_new_capa(mrb, 0);
+ v = mrb_ary_new_from_values(mrb, 1, &regs[a]);
+ }
+ ary = mrb_ary_ptr(v);
+ len = ary->len;
+ if (len > pre + post) {
+ regs[a++] = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
while (post--) {
- SET_NIL_VALUE(regs[a]);
- a++;
+ regs[a++] = ary->ptr[len-post-1];
}
}
else {
- struct RArray *ary = mrb_ary_ptr(v);
- int len = ary->len;
- int idx;
-
- if (len > pre + post) {
- regs[a++] = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
- while (post--) {
- regs[a++] = ary->ptr[len-post-1];
- }
+ regs[a++] = mrb_ary_new_capa(mrb, 0);
+ for (idx=0; idx+pre<len; idx++) {
+ regs[a+idx] = ary->ptr[pre+idx];
}
- else {
- regs[a++] = mrb_ary_new_capa(mrb, 0);
- for (idx=0; idx+pre<len; idx++) {
- regs[a+idx] = ary->ptr[pre+idx];
- }
- while (idx < post) {
- SET_NIL_VALUE(regs[a+idx]);
- idx++;
- }
+ while (idx < post) {
+ SET_NIL_VALUE(regs[a+idx]);
+ idx++;
}
}
ARENA_RESTORE(mrb, ai);