Hello,

On Tue, Jan 31, 2006 at 08:12:40PM +0200, Wladimir Mutel wrote:
> 
>       Here is the testcase. May be fgrep in some way distinguishes
>       between end-of-word and end-of-line, as my search samples were
>       words at the end of lines :

The attached patch should fix this bug in "fgrep -w".

In the first chunk, we need to check the next char because the previous
char is the beginning of a multibyte char.

In the second chunk, we match a word if the last matched char is not
the beginning of a multibyte char, OR if we are out of the buffer.

Kind Regards,
-- 
Nekral
diff -rauN ../orig/grep-2.5.1.ds2/debian/patches/64-egf-speedup.patch 
./grep-2.5.1.ds2/debian/patches/64-egf-speedup.patch
--- ../orig/grep-2.5.1.ds2/debian/patches/64-egf-speedup.patch  2006-05-16 
11:21:45.000000000 -0500
+++ ./grep-2.5.1.ds2/debian/patches/64-egf-speedup.patch        2006-05-16 
18:39:25.000000000 -0500
@@ -658,7 +658,7 @@
 +                  }
 +                else
 +#endif /* MBS_SUPPORT */
-+                if (!WCHAR ((unsigned char) beg[-1]))
++                if (WCHAR ((unsigned char) beg[-1]))
 +                  goto next_char;
 +              }
  #ifdef MBS_SUPPORT
@@ -685,7 +685,7 @@
 +            else
  #endif /* MBS_SUPPORT */
 -                  return offset;
-+              if (beg + len >= buf + size && !WCHAR ((unsigned char) 
beg[len]))
++              if (beg + len >= buf + size || !WCHAR ((unsigned char) 
beg[len]))
 +                word_match = 1;
 +            if (word_match)
 +              {

Reply via email to