From 54910755c76a6a04411afa613645cfb203ce1be0 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Tue, 2 Dec 2014 22:45:17 +0900 Subject: [PATCH 1/2] dfa: matching at next position or infinit loop in matching mode After failed to match in matching mode, dfa transits initial state when not allow newline or next state when allow new line instead of return NULL. That will cause next matching at position or infinit loop. By the way, theere is no affair for grep in order that it always uses not matching mode but searching mode. * src/dfa.c (dfaexec_main): After failed to match in matching mode return NULL instead of transition to next state. --- src/dfa.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index 65862e8..4ab2b72 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -3498,13 +3498,16 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, continue; } - if (p[-1] == eol && allow_nl) + if (p[-1] != eol || d->newlines[s1] < 0) { - s = d->newlines[s1]; - continue; + p = NULL; + goto done; } - s = 0; + if (allow_nl) + s = d->newlines[s1]; + else + s = 0; } done: -- 2.2.0