From efddc2309c5ff8a1842bea8a9c0d7d4a5d6e1e60 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 1 Apr 2026 15:01:58 -0300 Subject: Bug: wrong initialization in result from 'gmatch' Function returned by 'string.gmatch' can be left in an inconsistent state after an error. --- lstrlib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index 874cec80..dd3c0fd0 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -757,19 +757,25 @@ static int nospecials (const char *p, size_t l) { } +/* +** Prepare state for matches. These fields are not affected by each match. +*/ static void prepstate (MatchState *ms, lua_State *L, const char *s, size_t ls, const char *p, size_t lp) { ms->L = L; - ms->matchdepth = MAXCCALLS; ms->src_init = s; ms->src_end = s + ls; ms->p_end = p + lp; } +/* +** (Re)prepare state for a match, setting fields that change during +** each match. +*/ static void reprepstate (MatchState *ms) { + ms->matchdepth = MAXCCALLS; ms->level = 0; - lua_assert(ms->matchdepth == MAXCCALLS); } -- cgit v1.2.3-55-g6feb