aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lstrlib.c10
-rw-r--r--testes/pm.lua10
2 files changed, 18 insertions, 2 deletions
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) {
757} 757}
758 758
759 759
760/*
761** Prepare state for matches. These fields are not affected by each match.
762*/
760static void prepstate (MatchState *ms, lua_State *L, 763static void prepstate (MatchState *ms, lua_State *L,
761 const char *s, size_t ls, const char *p, size_t lp) { 764 const char *s, size_t ls, const char *p, size_t lp) {
762 ms->L = L; 765 ms->L = L;
763 ms->matchdepth = MAXCCALLS;
764 ms->src_init = s; 766 ms->src_init = s;
765 ms->src_end = s + ls; 767 ms->src_end = s + ls;
766 ms->p_end = p + lp; 768 ms->p_end = p + lp;
767} 769}
768 770
769 771
772/*
773** (Re)prepare state for a match, setting fields that change during
774** each match.
775*/
770static void reprepstate (MatchState *ms) { 776static void reprepstate (MatchState *ms) {
777 ms->matchdepth = MAXCCALLS;
771 ms->level = 0; 778 ms->level = 0;
772 lua_assert(ms->matchdepth == MAXCCALLS);
773} 779}
774 780
775 781
diff --git a/testes/pm.lua b/testes/pm.lua
index 720d2a35..feab33db 100644
--- a/testes/pm.lua
+++ b/testes/pm.lua
@@ -347,6 +347,16 @@ do -- init parameter in gmatch
347end 347end
348 348
349 349
350do -- bug since 5.3
351 local N = 20000
352 local iter = string.gmatch(string.rep("a", N), string.rep("a?", N))
353 pcall(iter) -- error for pattern too complex
354 -- calling function again found recursion count ('matchdepth') equal
355 -- to -1, so it did not detect next C-stack overflow
356 pcall(iter)
357end
358
359
350-- tests for `%f' (`frontiers') 360-- tests for `%f' (`frontiers')
351 361
352assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") 362assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x")