]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: fix failure in removal of epsilon closure
authorNorihiro Tanaka <noritnk@kcn.ne.jp>
Mon, 14 Sep 2020 13:21:05 +0000 (22:21 +0900)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 15 Sep 2020 20:46:11 +0000 (13:46 -0700)
If there are a espilon in a branch and the closure is iterated, maybe fails
in removal of the node.  The bug is introduced in
commit da0e8454a8e68035ef4b87dbb9097f85df6ece27.

* lib/dfa.c (dfaanalyze): Calculate backward transition for not only
concatenation but closure.

lib/dfa.c

index 746c7b56811c842b12dbd9602dafc8b1b63c7dd7..7851fab779e58c7cfbd9023dc45aa3e68f6d612b 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2701,6 +2701,17 @@ dfaanalyze (struct dfa *d, bool searchflag)
 
         case STAR:
         case PLUS:
+          /* Every element in the lastpos of the argument is in the backward
+             set of every element in the firstpos.  */
+          if (d->epsilon)
+            {
+              tmp.elems = lastpos - stk[-1].nlastpos;
+              tmp.nelem = stk[-1].nlastpos;
+              for (position *p = firstpos - stk[-1].nfirstpos;
+                   p < firstpos; p++)
+                merge2 (&backward[p->index], &tmp, &merged);
+            }
+
           /* Every element in the firstpos of the argument is in the follow
              of every element in the lastpos.  */
           {