Subject: Re: bug#21670: surprising bug in grep -e with anchors

From: Paul Eggert <[email-masked]>
Date: Tue, 13 Oct 2015 15:31:28 -0700

On 10/13/2015 06:30 AM, Norihiro Tanaka wrote:
> First patch fixes the bug.  After the patch is applied, bug#21670
> appears again.  And, second patch fixes bug#21670.
Thanks, I installed both of them after rewording the commit logs a bit, 
along with the attached minor further improvement.
>From f7a45f7f48c0e1cdd498ec44f462179e57d48640 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 13 Oct 2015 15:26:38 -0700
Subject: [PATCH] dfa: make the executable a bit smaller

* src/dfa.c (dfamust): Hoist MB_CUR_MAX calculation out of loops.
---
 src/dfa.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/dfa.c b/src/dfa.c
index cdea4e5..c1a00f8 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3942,6 +3942,7 @@ dfamust (struct dfa const *d)
   bool endline = false;
   bool need_begline = false;
   bool need_endline = false;
+  bool case_fold_unibyte = case_fold && MB_CUR_MAX == 1;
 
   for (size_t ri = 0; ri < d->tindex; ++ri)
     {
@@ -4108,7 +4109,7 @@ dfamust (struct dfa const *d)
               t = j;
               while (++j < NOTCHAR)
                 if (tstbit (j, *ccl)
-                    && ! (case_fold && MB_CUR_MAX == 1
+                    && ! (case_fold_unibyte
                           && toupper (j) == toupper (t)))
                   break;
               if (j < NOTCHAR)
@@ -4131,14 +4132,14 @@ dfamust (struct dfa const *d)
             }
           mp = allocmust (mp, ((rj - ri) >> 1) + 1);
           mp->is[0] = mp->left[0] = mp->right[0]
-            = case_fold && MB_CUR_MAX == 1 ? toupper (t) : t;
+            = case_fold_unibyte ? toupper (t) : t;
 
           for (i = 1; ri + 2 < rj; i++)
             {
               ri += 2;
               t = d->tokens[ri];
               mp->is[i] = mp->left[i] = mp->right[i]
-                = case_fold && MB_CUR_MAX == 1 ? toupper (t) : t;
+                = case_fold_unibyte ? toupper (t) : t;
             }
           mp->is[i] = mp->left[i] = mp->right[i] = '\0';
           mp->in = enlist (mp->in, mp->is, i);
-- 
2.1.0