From 5668ae1b29de7bf71b45e97d85b11b20bf32bc4f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 17 Nov 2013 17:24:37 +0900 Subject: [PATCH] [bugfix] local variables should be initialized before copied to env object --- src/vm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/vm.c b/src/vm.c index ce5fbcde..720cf119 100644 --- a/src/vm.c +++ b/src/vm.c @@ -525,6 +525,16 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) } PUSH(rest); } + /* prepare local variable area */ + if (proc->u.irep->localc > 0) { + int l = proc->u.irep->localc; + if (proc->u.irep->varg) { + --l; + } + for (i = 0; i < l; ++i) { + PUSH(pic_undef_value()); + } + } /* prepare env */ if (proc->u.irep->cv_num == 0) { @@ -540,15 +550,6 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) } } - /* prepare local variable area */ - if (proc->u.irep->localc > 0) { - int l = proc->u.irep->localc; - if (proc->u.irep->varg) { - --l; - } - pic->sp += l; - } - pc = proc->u.irep->code; pic_gc_arena_restore(pic, ai); JUMP;