Thanks, I installed your updated dfa.c patch into Gnulib, along with the attached cleanup patch.
>From 91e8dccc3c352d56262e24f8fc8d4b736092e639 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 15 Sep 2020 13:44:34 -0700
Subject: [PATCH] dfa: remove dfa-heap-overrun workaround

* lib/dfa.c (reorder_tokens): Go back to a single pass that
both sets map[*] and does other things.  This reverts
2020-09-14T01:20:01Z!egg...@cs.ucla.edu, which is no longer
needed now that 2020-09-14T13:21:05Z!nori...@kcn.ne.jp
fixed the underlying problem.
---
 ChangeLog |  9 +++++++++
 lib/dfa.c | 12 ++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 395ac6baf..b668fbd2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-09-15  Paul Eggert  <egg...@cs.ucla.edu>
+
+	dfa: remove dfa-heap-overrun workaround
+	* lib/dfa.c (reorder_tokens): Go back to a single pass that
+	both sets map[*] and does other things.  This reverts
+	2020-09-14T01:20:01Z!egg...@cs.ucla.edu, which is no longer
+	neeeded now that 2020-09-14T13:21:05Z!nori...@kcn.ne.jp
+	fixed the underlying problem.
+
 2020-09-13  Paul Eggert  <egg...@cs.ucla.edu>
 
 	dfa: avoid use of uninitialized constraint
diff --git a/lib/dfa.c b/lib/dfa.c
index 7851fab77..c25a39172 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2505,11 +2505,6 @@ reorder_tokens (struct dfa *d)
                           ? xnmalloc (d->nleaves, sizeof *multibyte_prop)
                           : NULL);
 
-  for (idx_t i = 0; i < d->tindex; i++)
-    for (idx_t j = 0; j < d->follows[i].nelem; j++)
-      if (map[d->follows[i].elems[j].index] < 0)
-        map[d->follows[i].elems[j].index] = nleaves++;
-
   for (idx_t i = 0; i < d->tindex; i++)
     {
       if (map[i] < 0)
@@ -2528,7 +2523,12 @@ reorder_tokens (struct dfa *d)
         multibyte_prop[map[i]] = d->multibyte_prop[i];
 
       for (idx_t j = 0; j < d->follows[i].nelem; j++)
-        d->follows[i].elems[j].index = map[d->follows[i].elems[j].index];
+        {
+          if (map[d->follows[i].elems[j].index] == -1)
+            map[d->follows[i].elems[j].index] = nleaves++;
+
+          d->follows[i].elems[j].index = map[d->follows[i].elems[j].index];
+        }
 
       qsort (d->follows[i].elems, d->follows[i].nelem,
              sizeof *d->follows[i].elems, compare);
-- 
2.17.1

Reply via email to