buggrep - Bugs: bug #25414, grep on win32 gives "not...

 
 

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

bug #25414: grep on win32 gives "not enough space" when reading from stdin

Submitted by:  Dimitry Andric <dim>
Submitted on:  Mon 26 Jan 2009 09:04:35 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Mon 26 Jan 2009 09:04:35 PM UTC, original submission:

I have built grep 2.5.3 successfully on Win32, using MinGW. This needed
just a few minor patches. The test suite mostly passes, except for
some in the infamous foad1.sh, which seem to have been commented out in
the HEAD version in CVS. :)

However, running grep in the following fashion:

grep foo

e.g. expecting it to read from stdin, you always get the error:

grep: (standard input): Not enough space

After some digging, I found out this is caused by the default read()
buffer size in fillbuf(), INITIAL_BUFSIZE, which is 32 kiB.

Now, for some unfathomable reason, Microsoft has not deemed the Win32
standard input handle to be able to read 32767 bytes. The actual Win32
ReadFile() API call fails with ENOMEM.

After some experimenting, I have determined that at least on my version
of Windows XP, the maximum input buffer size for stdin is 24546 bytes.

I would like to propose the following patch, which sets INITIAL_BUFSIZE
at 16384 bytes for Win32, which looks safely under the maximum. If you
would rather have this in a header file somewhere, please let me know.

diff -uprd grep-2.5.3-orig/src/grep.c grep-2.5.3/src/grep.c
--- grep-2.5.3-orig/src/grep.c Thu Jun 28 19:57:19 2007
+++ grep-2.5.3/src/grep.c Fri Jan 23 14:19:52 2009
@@ -412,7 +412,11 @@ context_length_arg (char const *str, int

static char buffer; / Base of buffer. */
static size_t bufalloc; /* Allocated buffer size, counting slop. */
+#ifdef _WIN32
+#define INITIAL_BUFSIZE 16384 /* Initial buffer size, not counting slop. */
+#else
#define INITIAL_BUFSIZE 32768 /* Initial buffer size, not counting slop. */
+#endif
static int bufdesc; /* File descriptor. */
static char bufbeg; / Beginning of user-visible stuff. */
static char buflim; / Limit of user-visible stuff. */

Dimitry Andric <dim>

 

Attached Files
file #17334:  grep-2.5.3-bufsize.patch added by dim (695B - text/x-diff - Patch to decrease INITIAL_BUFSIZE for Win32)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by dim (Submitted the item)
  •  

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

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 26 Jan 2009 09:06:31 PM UTCdimAttached File-=>Added grep-2.5.3-bufsize.patch, #17334

    Back to the top


    Powered by Savane 3.1-cleanup