Avoid duplicated `envadjust()` of env stacks; fix
MODIFY
src/vm.c
src/vm.c
@@ -115,14 +115,17 @@ stack_init(mrb_state *mrb)
}
static inline void
-envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase)
+envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size)
{
mrb_callinfo *ci = mrb->c->cibase;
if (newbase == oldbase) return;
while (ci <= mrb->c->ci) {
struct REnv *e = ci->env;
- if (e && MRB_ENV_STACK_SHARED_P(e)) {
+ mrb_value *st;
+
+ if (e && MRB_ENV_STACK_SHARED_P(e) &&
+ (st = e->stack) && oldbase <= st && st < oldbase+size) {
ptrdiff_t off = e->stack - oldbase;
e->stack = newbase + off;
@@ -164,7 +167,7 @@ stack_extend_alloc(mrb_state *mrb, int room)
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
}
stack_clear(&(newstack[oldsize]), size - oldsize);
- envadjust(mrb, oldbase, newstack);
+ envadjust(mrb, oldbase, newstack, size);
mrb->c->stbase = newstack;
mrb->c->stack = mrb->c->stbase + off;
mrb->c->stend = mrb->c->stbase + size;
@@ -297,7 +300,7 @@ ecall(mrb_state *mrb, int i)
mrb_callinfo *ci = mrb->c->ci;
mrb_value *self = mrb->c->stack;
struct RObject *exc;
- int cioff;
+ ptrdiff_t cioff;
if (i<0) return;
if (ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {

Avoid duplicated `envadjust()` of env stacks; fix #3637