From 3068e45799327298a3f4c22b03db2aa48e2ab0da Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 27 Aug 2021 12:18:58 -0400 Subject: Handle interaction of regexp's makesearch and MATCHALL more honestly. Second thoughts about commit 824bf7190: we apply makesearch() to an NFA after having determined whether it is a MATCHALL pattern. Prepending ".*" doesn't make it non-MATCHALL, but it does change the maximum possible match length, and makesearch() failed to update that. This has no ill effects given the stylized usage of search NFAs, but it seems like it's better to keep the data structure consistent. In particular, fixing this allows more honest handling of the MATCHALL check in matchuntil(): we can now assert that maxmatchall is infinity, instead of lamely assuming that it should act that way. In passing, improve the code in dump[c]nfa so that infinite maxmatchall is printed as "inf" not a magic number. --- src/backend/regex/regcomp.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/backend/regex/regcomp.c') diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c index bfe12eb08b3..b735fa6eaff 100644 --- a/src/backend/regex/regcomp.c +++ b/src/backend/regex/regcomp.c @@ -598,6 +598,13 @@ makesearch(struct vars *v, /* and ^* and \A* too -- not always necessary, but harmless */ newarc(nfa, PLAIN, nfa->bos[0], pre, pre); newarc(nfa, PLAIN, nfa->bos[1], pre, pre); + + /* + * The pattern is still MATCHALL if it was before, but the max match + * length is now infinity. + */ + if (nfa->flags & MATCHALL) + nfa->maxmatchall = DUPINF; } /* -- cgit v1.2.3