From 3be0bc551387911faf98d89dc076f39561a753f3 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Tue, 13 Oct 2015 01:19:43 +0900 Subject: [PATCH 2/2] dfa: fix bug in alternate of sub-patterns different in only the constraints A line may incorrectly matches alternate of sub-patterns different in only the constraints e.g. ^a|a$ in extended regular expression. This change fixes the bug. Reported by Greg Boyd in http://debbugs.gnu.org/21670 * src/dfa.c (dfamust): For a pattern with constraints, check that it is matched including the constraints, to judge whether it is exact. --- src/dfa.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dfa.c b/src/dfa.c index 5b9a4fe..cdea4e5 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -3940,6 +3940,8 @@ dfamust (struct dfa const *d) bool exact = false; bool begline = false; bool endline = false; + bool need_begline = false; + bool need_endline = false; for (size_t ri = 0; ri < d->tindex; ++ri) { @@ -3949,10 +3951,12 @@ dfamust (struct dfa const *d) case BEGLINE: mp = allocmust (mp, 2); mp->begline = true; + need_begline = true; break; case ENDLINE: mp = allocmust (mp, 2); mp->endline = true; + need_endline = true; break; case LPAREN: case RPAREN: @@ -4029,7 +4033,9 @@ dfamust (struct dfa const *d) result = mp->in[i]; if (STREQ (result, mp->is)) { - exact = true; + if ((!need_begline || mp->begline) && (!need_endline + || mp->endline)) + exact = true; begline = mp->begline; endline = mp->endline; } -- 2.4.1