bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep 2.4.2 incorrect handling of '[x^]'


From: Keith Owens
Subject: Re: grep 2.4.2 incorrect handling of '[x^]'
Date: Mon, 30 Jul 2001 17:21:16 +1000

>> # echo 123 | grep '[x^]'
>> 123

It is a bug introduced by a Redhat patch which is supposed to fix
another bug.  One bug in, one bug out.  Problem logged with RH.

grep-2.4.2-i18n.patch

The following patch works around the bug in grep which makes

        grep '[a-c]'

match "B".  Note, this is a bug in grep caused by a bug in the
standards which do not provide interfaces to get the necessary
information.  This patch as correct as grep was before (multibyte char
handling is not 100% correct but that cannot be solved now), future
changes might increase the speed a bit.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- grep-2.4.2/src/dfa.c-old    Sat Aug 19 17:55:05 2000
+++ grep-2.4.2/src/dfa.c        Sat Aug 19 17:55:11 2000
@@ -743,6 +743,7 @@ lex (void)
              else
                c2 = c;
 
+#if 0
              lo[0] = c;  lo[1] = '\0';
              hi[0] = c2; hi[1] = '\0';
              for (c = 0; c < NOTCHAR; c++)
@@ -761,6 +762,37 @@ lex (void)
                        }
                    }
                }
+#else
+             {
+               char expr[6] = { '[', c, '-', c2, ']', '\0' };
+               regex_t re;
+
+               if (regcomp (&re, expr, case_fold ? REG_ICASE : 0)
+                   == REG_NOERROR)
+                 {
+                   for (c = 0; c < NOTCHAR; ++c)
+                     {
+                       char buf[2] = { c, '\0' };
+                       regmatch_t mat;
+
+                       if (regexec (&re, buf, 1, &mat, 0) == REG_NOERROR
+                           && mat.rm_so == 0 && mat.rm_eo == 1)
+                         {
+                           setbit (c, ccl);
+                           if (case_fold)
+                             {
+                               if (ISUPPER (c))
+                                 setbit (tolower (c), ccl);
+                               else if (ISLOWER (c))
+                                 setbit (toupper (c), ccl);
+                             }
+                         }
+                     }
+
+                   regfree (&re);
+                 }
+             }
+#endif
 
            skip:
              ;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




reply via email to

[Prev in Thread] Current Thread [Next in Thread]