Skip to content

Commit

Permalink
The stack may be reallocated in the func call; fix #3560
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 1, 2017
1 parent 8d9d7c9 commit 1e87dfd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1449,13 +1449,16 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
mrb->c->stack[0] = recv;

if (MRB_PROC_CFUNC_P(m)) {
mrb_value v;

if (n == CALL_MAXARGS) {
ci->nregs = 3;
}
else {
ci->nregs = n + 2;
}
mrb->c->stack[0] = m->body.func(mrb, recv);
v = m->body.func(mrb, recv);
mrb->c->stack[0] = v;
mrb_gc_arena_restore(mrb, ai);
if (mrb->exc) goto L_RAISE;
/* pop stackpos */
Expand Down Expand Up @@ -1862,7 +1865,8 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
value_move(mrb->c->stack, &regs[a], ci->argc+1);

if (MRB_PROC_CFUNC_P(m)) {
mrb->c->stack[0] = m->body.func(mrb, recv);
mrb_value v = m->body.func(mrb, recv);
mrb->c->stack[0] = v;
mrb_gc_arena_restore(mrb, ai);
goto L_RETURN;
}
Expand Down

0 comments on commit 1e87dfd

Please sign in to comment.