> When grep exhausts memory due to trying to read() > or mmap() a large binary file, it prints > > grep: memory exhausted > > on stderr, then exits with exit status, 1. > > I expect the failure, but I believe that > it should exit(2), or something greater than 1, > in order to distinguish this type of failure > from simply a failure to find a match.
Thanks, this should be enough to fix it: diff --git a/src/main.c b/src/main.c index b7d1c78..500c473 100644 --- a/src/main.c +++ b/src/main.c @@ -1773,6 +1773,7 @@ main (int argc, char **argv) int default_context; FILE *fp; + exit_failure = EXIT_TROUBLE; initialize_main (&argc, &argv); set_program_name (argv[0]); program_name = argv[0]; diff --git a/NEWS b/NEWS index 539e978..bd75640 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ GNU grep NEWS -*- outline -*- support was introduced in 2.5.2, though the steps needed to reproduce it changed in grep-2.6] + grep erroneously returned with exit status 1 on some memory allocation + failure. [bug present since "the beginning"] + * Noteworthy changes in release 2.7 (2010-09-16) [stable] ** Bug fixes The bug is present since grep started using xmalloc commit 832757b094adc56acf2dd728de1f2459228d1fdf Author: Alain Magloire <[email protected]> Date: Sun Mar 4 05:33:12 2001 +0000 from GNU tar and fetish. which is why I'm marking it as "present since the beginning" in NEWS. Paolo
