From df54de37b0a372a49bed0130406a5b75b85cd119 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Tue, 21 Nov 2023 11:29:30 +1100 Subject: Bug [#2413]. Fix regular expression search failure. --- src/RESearch.cxx | 23 ++++++++++++++--------- src/RESearch.h | 3 +-- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/RESearch.cxx b/src/RESearch.cxx index ca0f1b552..ac41138c8 100644 --- a/src/RESearch.cxx +++ b/src/RESearch.cxx @@ -256,8 +256,7 @@ RESearch::RESearch(CharClassify *charClassTable) { bol = 0; constexpr unsigned char nul = 0; std::fill(bittab, std::end(bittab), nul); - std::fill(tagstk, std::end(tagstk), 0); - std::fill(nfa, std::end(nfa), '\0'); + nfa[0] = END; Clear(); } @@ -419,12 +418,24 @@ int RESearch::GetBackslashExpression( return result; } -const char *RESearch::Compile(const char *pattern, Sci::Position length, bool caseSensitive, bool posix) noexcept { +const char *RESearch::Compile(const char *pattern, Sci::Position length, bool caseSensitive, bool posix) { + if (!pattern || !length) { + if (sta) + return nullptr; + else + return badpat("No previous regular expression"); + } + + constexpr unsigned char nul = 0; + std::fill(bittab, std::end(bittab), nul); + nfa[0] = END; + char *mp=nfa; /* nfa pointer */ char *lp=nullptr; /* saved pointer */ char *sp=nfa; /* another one */ const char * mpMax = mp + MAXNFA - BITBLK - 10; + int tagstk[MAXTAG]{}; /* subpat tag stack */ int tagi = 0; /* tag stack index */ int tagc = 1; /* actual tag count */ @@ -434,12 +445,6 @@ const char *RESearch::Compile(const char *pattern, Sci::Position length, bool ca int c2 = 0; int prevChar = 0; - if (!pattern || !length) { - if (sta) - return nullptr; - else - return badpat("No previous regular expression"); - } sta = NOP; const char *p=pattern; /* pattern pointer */ diff --git a/src/RESearch.h b/src/RESearch.h index 05bc0e093..5ac3f00dc 100644 --- a/src/RESearch.h +++ b/src/RESearch.h @@ -22,7 +22,7 @@ public: explicit RESearch(CharClassify *charClassTable); // No dynamic allocation so default copy constructor and assignment operator are OK. void Clear(); - const char *Compile(const char *pattern, Sci::Position length, bool caseSensitive, bool posix) noexcept; + const char *Compile(const char *pattern, Sci::Position length, bool caseSensitive, bool posix); int Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp); static constexpr int MAXTAG = 10; @@ -48,7 +48,6 @@ private: Sci::Position PMatch(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp, const char *ap); Sci::Position bol; - Sci::Position tagstk[MAXTAG]; /* subpat tag stack */ char nfa[MAXNFA]; /* automaton */ int sta; unsigned char bittab[BITBLK]; /* bit table for CCL pre-set bits */ -- cgit v1.2.3