diff options
author | Jim Meyering <meyering@fb.com> | 2022-03-20 09:43:30 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2022-03-20 13:23:58 -0700 |
commit | 6e95551ad6a1e5591ea0d417c2d3eec1921e48b5 (patch) | |
tree | 0cd066f97421a57350bb7b1f1b7d3bb9b4cea7f9 /src | |
parent | efe1e1543c409504752f8d240d3ea41af3b8fddf (diff) | |
download | grep-6e95551ad6a1e5591ea0d417c2d3eec1921e48b5.tar.gz |
grep: very long lines no longer evoke unwarranted "memory exhausted"
When calling xpalloc (NULL, &n, incr_min, alloc_max, 1) with
nontrivial ALLOC_MAX, this must hold: N + INCR_MIN <= ALLOC_MAX.
With a very long line, it did not, and grep would mistakenly fail
with a report of "memory exhausted".
* src/grep.c (fillbuf): When using nontrivial ALLOC_MAX, ensure it
is at least N+INCR_MIN.
* tests/fillbuf-long-line: New file, to test for this.
* tests/Makefile.am (TESTS): Add its name.
Diffstat (limited to 'src')
-rw-r--r-- | src/grep.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -984,7 +984,7 @@ fillbuf (idx_t save, struct stat const *st) ptrdiff_t a; if (0 <= to_be_read && INT_ADD_OK (to_be_read, save + min_after_buflim, &a)) - alloc_max = a; + alloc_max = MAX (a, bufalloc + incr_min); } newbuf = xpalloc (NULL, &bufalloc, incr_min, alloc_max, 1); |