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

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

Bug in grep-2.5.1 patch added.


From: Thomas Steudten
Subject: Bug in grep-2.5.1 patch added.
Date: Wed, 10 Mar 2004 23:14:54 +0100

Hello

Problem see: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=72641

Test with: echo "one tEst here" | grep -X -i --color=auto TEST and with
-o, fails with X:none,G,E and runs fine with X:F,P.

PATCH:
See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=72641 (sent upstream)
--- grep-2.5.1/src/search.c.orig        2004-03-10 14:09:09.000000000 +0100
+++ grep-2.5.1/src/search.c     2004-03-10 21:30:14.000000000 +0100
@@ -187,8 +187,10 @@
 {
   const char *err;
   char const *sep;
+  char *trans;
   size_t total = size;
   char const *motif = pattern;
+  int i;

   re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE);
dfasyntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE, match_icase, eolbyte);
@@ -197,6 +199,18 @@
      errors like "[\nallo\n]\n".  The patterns here are "[", "allo" and "]"
      GNU regex should have raise a syntax error.  The same for backref, where
      the backref should have been local to each pattern.  */
+
+   /* Fix for -i ignore-case default grep
+   ** Thomas Steudten <address@hidden>, 03/10/2004
+   */
+   if (match_icase)
+   {
+     char *trans = xmalloc (size);
+     for (i = 0; i < size; ++i)
+       *(trans+i) = TOLOWER ( *(motif+i));
+     motif = trans;
+   }
+
   do
     {
       size_t len;
@@ -215,13 +229,28 @@

       patterns = realloc (patterns, (pcount + 1) * sizeof (*patterns));
       if (patterns == NULL)
-       error (2, errno, _("memory exhausted"));
+      {
+        int err = errno;
+        if (match_icase && trans)
+        {
+           free(trans);
+           trans = NULL;
+        }
+       error (2, err, _("memory exhausted"));
+      }

       patterns[pcount] = patterns0;

       if ((err = re_compile_pattern (motif, len,
                                    &(patterns[pcount].regexbuf))) != 0)
+      {
+        if (match_icase && trans)
+        {
+           free(trans);
+           trans = NULL;
+        }
        error (2, 0, err);
+      }
       pcount++;

       motif = sep;
@@ -253,6 +282,11 @@
       pattern = n;
       size = i;
     }
+    if (match_icase && trans)
+    {
+       free(trans);
+       trans = NULL;
+    }

   dfacomp (pattern, size, &dfa, 1);
   kwsmusts ();
@@ -263,8 +297,10 @@
 {
   const char *err;
   const char *sep;
+  char *trans;
   size_t total = size;
   char const *motif = pattern;
+  int i;

   if (strcmp (matcher, "awk") == 0)
     {
@@ -281,6 +317,18 @@
      errors like "[\nallo\n]\n".  The patterns here are "[", "allo" and "]"
      GNU regex should have raise a syntax error.  The same for backref, where
      the backref should have been local to each pattern.  */
+
+   /* Fix for -i ignore-case egrep
+   ** Thomas Steudten <address@hidden>, 03/10/2004
+   */
+   if (match_icase)
+   {
+     char *trans = xmalloc (size);
+     for (i = 0; i < size; ++i)
+       *(trans+i) = TOLOWER ( *(motif+i));
+     motif = trans;
+   }
+
   do
     {
       size_t len;
@@ -299,12 +347,27 @@

       patterns = realloc (patterns, (pcount + 1) * sizeof (*patterns));
       if (patterns == NULL)
-       error (2, errno, _("memory exhausted"));
+      {
+        int err = errno;
+        if (match_icase && trans)
+        {
+                free(trans);
+                trans = NULL;
+        }
+        error (2, err, _("memory exhausted"));
+      }
       patterns[pcount] = patterns0;

       if ((err = re_compile_pattern (motif, len,
                                    &(patterns[pcount].regexbuf))) != 0)
-       error (2, 0, err);
+      {
+        if (match_icase && trans)
+        {
+                free(trans);
+                trans = NULL;
+        }
+        error (2, 0, err);
+      }
       pcount++;

       motif = sep;
@@ -336,6 +399,11 @@
       pattern = n;
       size = i;
     }
+    if (match_icase && trans)
+    {
+        free(trans);
+        trans = NULL;
+    }

   dfacomp (pattern, size, &dfa, 1);
   kwsmusts ();


--
Tom

LINUX user since kernel 0.99.x 1994.
RPM Alpha packages at http://alpha.steudten.com/packages
Want to know what S.u.S.E 1995 cdrom-set contains?







reply via email to

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