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

 
 

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

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

Submitter:  Dimitry Andric <dim>
Submitted:  Mon 26 Jan 2009 09:04:35 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned 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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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
  • -email is unavailable- added by dim (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-01-26 dim Attached File- Added grep-2.5.3-bufsize.patch, #17334

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code