From acff3ad88db13bb6d74170a3db475a4e45ddb51f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 23 Mar 2016 14:12:17 -0300 Subject: bug: 'gmatch' iterator fails when called from a coroutine different from the one that created it --- lstrlib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index 2f9dbf0f..c07cdbb7 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.239 2015/11/25 16:28:17 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.240 2016/02/25 19:42:55 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -688,14 +688,13 @@ typedef struct GMatchState { static int gmatch_aux (lua_State *L) { GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3)); const char *src; + gm->ms.L = L; for (src = gm->src; src <= gm->ms.src_end; src++) { const char *e; reprepstate(&gm->ms); if ((e = match(&gm->ms, src, gm->p)) != NULL) { - if (e == src) /* empty match? */ - gm->src =src + 1; /* go at least one position */ - else - gm->src = e; + /* in empty matches, advance at least one position */ + gm->src = (e == src) ? src + 1 : e; return push_captures(&gm->ms, src, e); } } -- cgit v1.2.3-55-g6feb