Initialization of too many locals break assertion

The check for limit of local variables is made after generating code to
initialize them. If there are too many local variables not initialized,
the coding of instruction OP_LOADNIL could overflow an argument.
This commit is contained in:
Roberto I
2025-10-10 13:22:19 -03:00
parent 25c54fe60e
commit 3347c9d32d
2 changed files with 13 additions and 7 deletions

View File

@@ -547,6 +547,7 @@ static void singlevar (LexState *ls, expdesc *var) {
static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
FuncState *fs = ls->fs;
int needed = nvars - nexps; /* extra values needed */
luaK_checkstack(fs, needed);
if (hasmultret(e->k)) { /* last expression has multiple returns? */
int extra = needed + 1; /* discount last expression itself */
if (extra < 0)