buggrep - Bugs: bug #17274, grep -Fw gives strange results

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #17274: grep -Fw gives strange results

Submitted by:  Christoph Bussenius <betterworld>
Submitted on:  Thu 03 Aug 2006 02:17:22 AM UTC  
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Fri 04 Dec 2009 07:27:20 PM UTC, comment #3: 

Closing per comment #2

Paolo Bonzini <bonzini>
Thu 03 Aug 2006 10:21:20 AM UTC, comment #2: 

Sorry, didn't read far enough.  It was ultimately fixed by a modified version of patch #4604 .

Benno Schulenberg <bens>
Thu 03 Aug 2006 10:17:46 AM UTC, comment #1: 

Thanks for the report.  This error appears to be fixed in CVS:

$ echo -e 'blah blubb\nb' | grep -Fw b
b

$ echo -e 'DESKTOP\nCDRW DUALXP SATA DE' | grep -Fw DE
CDRW DUALXP SATA DE

$ grep --version | head -1
GNU grep 2.5.1-cvs

It was fixed probably by the commit on April 27 last year, mainly as a rection to patch #1834 .  Apparenlty not all distros apply the same patches to their greps.  This is the essential diff:

--- src/search.c        9 Mar 2005 13:11:28 -0000       1.34
+++ src/search.c        27 Apr 2005 18:30:29 -0000      1.35
@@ -599,17 +599,7 @@
              {
                offset = kwsexec (kwset, beg, --len, &kwsmatch);
                if (offset == (size_t) -1)
-                 {
-#ifdef MBS_SUPPORT
-                    if (MB_CUR_MAX > 1)
-                      {
-                        if (match_icase)
-                          free ((char*)buf);
-                        free(mb_properties);
-                      }
-#endif /* MBS_SUPPORT */
-                   return offset;
-                 }
+                 break;
                try = beg + offset;
                len = kwsmatch.size[0];
              }

Benno Schulenberg <bens>
Thu 03 Aug 2006 02:17:22 AM UTC, original submission:  

I've tried the following command on sevaral systems (each had GNU grep-2.5.1 installed):

echo -e 'blah blubb\nb' | grep -Fw b

This printed both lines ("blah blubb\nb") System 1 and System 4, whereas Systems 2 and 3 did not print anything.  However, in my opinion, the correct output would have been "b", since this is the only line that contains b as a word.

echo -e 'DESKTOP\nCDRW DUALXP SATA DE' | grep -Fw DE

This gave the correct output ("CDRW DUALXP SATA DE") on Systems 1 and 4, but Systems 2 and 3 did not print anything.

Apparently, grep -Fw gets confused when encountering the search string ("b" or "DE") within a word (like "blah" or "DESKTOP", respectively).  If there are no words that include the search string as a substring, the output is as expected.  Also, the output is as expected when you don't use -F.

The systems I tested are:
1: Gentoo Linux, GNU grep 2.5.1
2: Debian Sarge, GNU grep 2.5.1
3: Suse 9.2, GNU grep 2.5.1
4: Red Hat Enterprise Linux ES release 3, GNU grep 2.5.1

Christoph Bussenius <betterworld>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bonzini (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-12-04 bonzini Open/ClosedOpen => Closed

    Back to the top


    Powered by Savane 3.6