From b58512a1531b0a6a8e61390edee0d4910648bae9 Mon Sep 17 00:00:00 2001 From: stanton Date: Wed, 9 Dec 1998 20:31:12 +0000 Subject: * generic/regcomp.c (makescan): Fixed bug in longest match case that caused anchored patterns to fail. [Bug: 897] --- generic/regcomp.c | 35 +++++++++++++++++------------------ tests/reg.test | 1 + 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/generic/regcomp.c b/generic/regcomp.c index a82eb96..02a65c7 100644 --- a/generic/regcomp.c +++ b/generic/regcomp.c @@ -481,27 +481,26 @@ struct nfa *nfa; struct arc *b; struct state *pre = nfa->pre; struct state *s; - struct state *s2; - struct state *slist; - - /* no changes are needed if it's anchored */ - for (a = pre->outs; a != NULL; a = a->outchain) { + struct state *s2; + struct state *slist; + + /* no loops are needed if it's anchored */ + for (a = pre->outs; a != NULL; a = a->outchain) { assert(a->type == PLAIN); if (a->co != nfa->bos[0] && a->co != nfa->bos[1]) break; - } - if (a == NULL) - return; - - /* add implicit .* in front */ - rainbow(nfa, v->cm, PLAIN, COLORLESS, pre, pre); - - /* and ^* and \Z* too -- not always necessary, but harmless */ - newarc(nfa, PLAIN, nfa->bos[0], pre, pre); - newarc(nfa, PLAIN, nfa->bos[1], pre, pre); - - /* - * Now here's the subtle part. Because many REs have no lookback + } + if (a != NULL) { + /* add implicit .* in front */ + rainbow(nfa, v->cm, PLAIN, COLORLESS, pre, pre); + + /* and ^* and \Z* too -- not always necessary, but harmless */ + newarc(nfa, PLAIN, nfa->bos[0], pre, pre); + newarc(nfa, PLAIN, nfa->bos[1], pre, pre); + } + + /* + * Now here's the subtle part. Because many REs have no lookback * constraints, often knowing when you were in the pre state tells * you little; it's the next state(s) that are informative. But * some of them may have other inarcs, i.e. it may be possible to diff --git a/tests/reg.test b/tests/reg.test index 26a981e..32b8dde 100644 --- a/tests/reg.test +++ b/tests/reg.test @@ -874,6 +874,7 @@ e 1 & *** BADRPT m 2 N a?b* abb abb m 3 N a?b* bb bb m 4 & a*b aab aab +m 5 & ^a*b aaaab aaaab -- cgit v0.12