Unverified Commit aa5c5de4 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4033 from i110/i110/fix-envadjust

fix env->stack misadjusting: fix #4029
parents 39526074 edaa7a1b
...@@ -141,7 +141,7 @@ stack_init(mrb_state *mrb) ...@@ -141,7 +141,7 @@ stack_init(mrb_state *mrb)
} }
static inline void static inline void
envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size) envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t oldsize)
{ {
mrb_callinfo *ci = mrb->c->cibase; mrb_callinfo *ci = mrb->c->cibase;
...@@ -151,7 +151,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size) ...@@ -151,7 +151,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size)
mrb_value *st; mrb_value *st;
if (e && MRB_ENV_STACK_SHARED_P(e) && if (e && MRB_ENV_STACK_SHARED_P(e) &&
(st = e->stack) && oldbase <= st && st < oldbase+size) { (st = e->stack) && oldbase <= st && st < oldbase+oldsize) {
ptrdiff_t off = e->stack - oldbase; ptrdiff_t off = e->stack - oldbase;
e->stack = newbase + off; e->stack = newbase + off;
...@@ -161,7 +161,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size) ...@@ -161,7 +161,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size)
e = MRB_PROC_ENV(ci->proc); e = MRB_PROC_ENV(ci->proc);
if (e && MRB_ENV_STACK_SHARED_P(e) && if (e && MRB_ENV_STACK_SHARED_P(e) &&
(st = e->stack) && oldbase <= st && st < oldbase+size) { (st = e->stack) && oldbase <= st && st < oldbase+oldsize) {
ptrdiff_t off = e->stack - oldbase; ptrdiff_t off = e->stack - oldbase;
e->stack = newbase + off; e->stack = newbase + off;
...@@ -205,7 +205,7 @@ stack_extend_alloc(mrb_state *mrb, int room) ...@@ -205,7 +205,7 @@ stack_extend_alloc(mrb_state *mrb, int room)
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err)); mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
} }
stack_clear(&(newstack[oldsize]), size - oldsize); stack_clear(&(newstack[oldsize]), size - oldsize);
envadjust(mrb, oldbase, newstack, size); envadjust(mrb, oldbase, newstack, oldsize);
mrb->c->stbase = newstack; mrb->c->stbase = newstack;
mrb->c->stack = mrb->c->stbase + off; mrb->c->stack = mrb->c->stbase + off;
mrb->c->stend = mrb->c->stbase + size; mrb->c->stend = mrb->c->stbase + size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment