From 3228a97c6a953dcf397944161bb64b12f1ff5384 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 23 Apr 2026 17:57:42 -0300 Subject: Bug: 'lua_load' does not preserve the stack 'lua_load' does not preserve the stack through the calls to the reader function, as it should. Immediately after the first call (to detect whether chunk is binary) it adds stuff, and it also adds a new table when starting the compilation of each new function. --- lundump.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lundump.c') diff --git a/lundump.c b/lundump.c index 3b61cc8c..d5fdc64b 100644 --- a/lundump.c +++ b/lundump.c @@ -392,7 +392,8 @@ static void checkHeader (LoadState *S) { /* ** Load precompiled chunk. */ -LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { +LClosure *luaU_undump (lua_State *L, ZIO *Z, Table *anchor, const char *name, + int fixed) { LoadState S; LClosure *cl; if (*name == '@' || *name == '=') @@ -405,20 +406,16 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { S.fixed = cast_byte(fixed); S.offset = 1; /* fist byte was already read */ checkHeader(&S); - cl = luaF_newLclosure(L, loadByte(&S)); - setclLvalue2s(L, L->top.p, cl); - luaD_inctop(L); - S.h = luaH_new(L); /* create list of saved strings */ + S.h = anchor; S.nstr = 0; - sethvalue2s(L, L->top.p, S.h); /* anchor it */ - luaD_inctop(L); + cl = luaF_newLclosure(L, loadByte(&S)); + luaD_anchorobj(L, anchor, obj2gco(cl)); cl->p = luaF_newproto(L); luaC_objbarrier(L, cl, cl->p); loadFunction(&S, cl->p); if (cl->nupvalues != cl->p->sizeupvalues) error(&S, "corrupted chunk"); luai_verifycode(L, cl->p); - L->top.p--; /* pop table */ return cl; } -- cgit v1.2.3-55-g6feb