diff --git a/src/grep.c b/src/grep.c index 9c933e4..4109ae4 100644 --- a/src/grep.c +++ b/src/grep.c @@ -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); diff --git a/tests/Makefile.am b/tests/Makefile.am index 04a9eee..708980d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -104,6 +104,7 @@ TESTS = \ fgrep-longest \ file \ filename-lineno.pl \ + fillbuf-long-line \ fmbtest \ foad1 \ grep-dev-null \ diff --git a/tests/fillbuf-long-line b/tests/fillbuf-long-line new file mode 100755 index 0000000..5a8d339 --- /dev/null +++ b/tests/fillbuf-long-line @@ -0,0 +1,11 @@ +#!/bin/sh +# This would fail for v3.7-15-ge3694e9 .. grep-v3.7-48-g5c3c427 +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +printf %0104681d 0 > in || framework_failure_ + +fail=0 + +returns_ 1 grep xx in || fail=1 + +Exit $fail