فهرست منبع

Bug when growing a stack

When a stack grows, its extra area can be in use, and it becomes part
of the common area. So, the extra area must be kept correct all the
times. (Bug introduced by commit 5aa36e894f5.)
Roberto Ierusalimschy 4 سال پیش
والد
کامیت
d282652561
3فایلهای تغییر یافته به همراه4 افزوده شده و 4 حذف شده
  1. 1 1
      ldo.c
  2. 2 2
      lgc.c
  3. 1 1
      lstate.c

+ 1 - 1
ldo.c

@@ -192,7 +192,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
     else return 0;  /* do not raise an error */
     else return 0;  /* do not raise an error */
   }
   }
   for (; lim < newsize; lim++)
   for (; lim < newsize; lim++)
-    setnilvalue(s2v(newstack + lim)); /* erase new segment */
+    setnilvalue(s2v(newstack + lim + EXTRA_STACK)); /* erase new segment */
   correctstack(L, L->stack, newstack);
   correctstack(L, L->stack, newstack);
   L->stack = newstack;
   L->stack = newstack;
   L->stack_last = L->stack + newsize;
   L->stack_last = L->stack + newsize;

+ 2 - 2
lgc.c

@@ -632,8 +632,8 @@ static int traversethread (global_State *g, lua_State *th) {
   for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)
   for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)
     markobject(g, uv);  /* open upvalues cannot be collected */
     markobject(g, uv);  /* open upvalues cannot be collected */
   if (g->gcstate == GCSatomic) {  /* final traversal? */
   if (g->gcstate == GCSatomic) {  /* final traversal? */
-    for (; o < th->stack_last; o++)  /* clear not-marked stack slice */
-      setnilvalue(s2v(o));
+    for (; o < th->stack_last + EXTRA_STACK; o++)
+      setnilvalue(s2v(o));  /* clear dead stack slice */
     /* 'remarkupvals' may have removed thread from 'twups' list */
     /* 'remarkupvals' may have removed thread from 'twups' list */
     if (!isintwups(th) && th->openupval != NULL) {
     if (!isintwups(th) && th->openupval != NULL) {
       th->twups = g->twups;  /* link it back to the list */
       th->twups = g->twups;  /* link it back to the list */

+ 1 - 1
lstate.c

@@ -181,7 +181,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
   int i; CallInfo *ci;
   int i; CallInfo *ci;
   /* initialize stack array */
   /* initialize stack array */
   L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
   L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
-  for (i = 0; i < BASIC_STACK_SIZE; i++)
+  for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++)
     setnilvalue(s2v(L1->stack + i));  /* erase new stack */
     setnilvalue(s2v(L1->stack + i));  /* erase new stack */
   L1->top = L1->stack;
   L1->top = L1->stack;
   L1->stack_last = L1->stack + BASIC_STACK_SIZE;
   L1->stack_last = L1->stack + BASIC_STACK_SIZE;