[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
avoid an unwarranted "memory exhausted"
From: |
Jim Meyering |
Subject: |
avoid an unwarranted "memory exhausted" |
Date: |
Sun, 20 Mar 2022 13:25:01 -0700 |
I was surprised to see a false report of "memory exhausted". This fixes it.
I've also tweaked configure.ac for warning-enabled builds on some systems:
>From 01103f62481f8b6d59dc1aba5c2460532bc75012 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sun, 20 Mar 2022 09:43:30 -0700
Subject: [PATCH 1/2] 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.
---
src/grep.c | 2 +-
tests/Makefile.am | 1 +
tests/fillbuf-long-line | 11 +++++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
create mode 100755 tests/fillbuf-long-line
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
--
2.35.1.273.ge6ebfd0e8c
>From 08d68a84adeb7270485a971b9045a01a53603402 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sun, 20 Mar 2022 11:05:31 -0700
Subject: [PATCH 2/2] build: avoid build failure on systems that must compile
regexec.c
With --enable-gcc-warnings, compiling regexec.h would fail due to
its use of a single variable-length array.
* configure.ac: Add -Wvla to the list of disabled warnings and
remove most of the others, that no longer need to be disabled.
---
configure.ac | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/configure.ac b/configure.ac
index 98d757a..0a97982 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,18 +128,9 @@ if test $gl_gcc_warnings != no; then
nw=$ew
# This, $nw, is the list of warnings we disable.
- nw="$nw -Wdeclaration-after-statement" # too useful to forbid
- nw="$nw -Waggregate-return" # anachronistic
- nw="$nw -Wlong-long" # C90 is anachronistic (lib/gethrxtime.h)
- nw="$nw -Wc++-compat" # We don't care about C++ compilers
- nw="$nw -Wundef" # Warns on '#if GNULIB_FOO' etc in gnulib
+ nw="$nw -Wvla" # suppress a warning in regexec.h
nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings
- nw="$nw -Wpadded" # Our structs are not padded
- nw="$nw -Wstack-protector" # generates false alarms for useful code
- nw="$nw -Wswitch-default" # Too many warnings for now
- nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
- nw="$nw -Winline" # streq.h's streq4, streq6 and strcaseeq6
- nw="$nw -Wstrict-overflow" # regexec.c
+
gl_MANYWARN_ALL_GCC([ws])
gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
--
2.35.1.273.ge6ebfd0e8c
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- avoid an unwarranted "memory exhausted",
Jim Meyering <=