Building the current grep (git master) with the current Gnulib, I see a test
failure on CentOS 7:


FAIL: test-mbrlen-1.sh
======================

../../gnulib-tests/test-mbrlen.c:47: assertion 'ret == (size_t)(-2)' failed
../../gnulib-tests/test-mbrlen-1.sh: line 5: 31796 Aborted                 
(core dumped) LC_ALL=C ${CHECKER} ./test-mbrlen${EXEEXT} 1
FAIL test-mbrlen-1.sh (exit status: 1)


The background is that mbrlen, on glibc systems <= 2.19, has a bug [1]:
This function returns 0 instead of @code{(size_t) -2} when the input
is empty.
This affects old distros:
  - CentOS 7 (glibc 2.17),
  - Slackware 14 (glibc 2.15),
  - openSUSE 12.1 (glibc 2.14.1),
  - etc.

mbrtowc has the same bug.

Gnulib has workarounds against this bug both in mbrlen and mbrtowc.

But grep deactivates the workaround for mbrtowc, in order not to
slow down 'grep' [2]. When this commit was created, Gnulib had a
mbrtowc-tests module. Now, since 2023-03-30, it also has an mbrlen-tests
module, and it is not deactivated. It fails because
  - mbrlen.m4 detects that mbrlen has the bug.
  - So it activates the replacement REPLACE_MBRLEN=1.
  - The replacement invokes mbrtowc.
  - But mbrtowc is not fixed, due to [2].

I see two reasonable fixes:

a) Remove the special optimization for CentOS 7. This distro will become
unsupported in less than a month [3], therefore it is no longer necessary
to carry complexity to optimize it.
-> patch 0001-maint-Remove-special-optimization-for-CentOS-7.patch

b) Extend the special optimization also to the mbrlen function and tests.
-> 0001-maint-Avoid-test-mbrlen-1.sh-failure-on-CentOS-7.patch

For each of the fixes, find a proposed patch (untested) attached.

Bruno

[1] https://www.gnu.org/software/gnulib/manual/html_node/mbrlen.html
[2] 
https://git.savannah.gnu.org/gitweb/?p=grep.git;a=commitdiff;h=6e319a818ed7b15b452ed2baab2f6a38d42fd1fe
[3] 
https://git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=blob;f=end-of-life.txt;h=5b7ff5559f3ddc9ea753f7837c35e8efbe0a8100;hb=HEAD
>From 3c4875e5a970465dd761c0ac63544f10c01975ff Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Mon, 10 Jun 2024 13:30:49 +0200
Subject: [PATCH] maint: Remove special optimization for CentOS 7.

* configure.ac (gl_cv_func_mbrtowc_empty_input): Don't set.
* bootstrap.conf (avoided_gnulib_modules): Remove mbrtowc-tests.
---
 bootstrap.conf | 1 -
 configure.ac   | 5 -----
 2 files changed, 6 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 178aca9..8d3c541 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -19,7 +19,6 @@ avoided_gnulib_modules='
   --avoid=lock-tests
   --avoid=mbuiter
   --avoid=mbuiterf
-  --avoid=mbrtowc-tests
   --avoid=update-copyright-tests
 '
 
diff --git a/configure.ac b/configure.ac
index 3d630a2..bcbbb62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,11 +53,6 @@ gl_EARLY
 AC_PROG_RANLIB
 PKG_PROG_PKG_CONFIG([0.9.0])
 
-# grep never invokes mbrtowc or mbrlen on empty input,
-# so don't worry about this common bug,
-# as working around it would merely slow grep down.
-gl_cv_func_mbrtowc_empty_input='assume yes'
-
 dnl Checks for typedefs, structures, and compiler characteristics.
 gl_INIT
 
-- 
2.34.1

>From 3902dba55ac7e126f5c1babfddac6f816de1d0d1 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Mon, 10 Jun 2024 13:35:16 +0200
Subject: [PATCH] maint: Avoid test-mbrlen-1.sh failure on CentOS 7.

* configure.ac: Pre-set gl_cv_func_mbrlen_empty_input.
* bootstrap.conf (avoided_gnulib_modules): Avoid also mbrlen-tests.
---
 bootstrap.conf | 1 +
 configure.ac   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/bootstrap.conf b/bootstrap.conf
index 178aca9..4358ab5 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -19,6 +19,7 @@ avoided_gnulib_modules='
   --avoid=lock-tests
   --avoid=mbuiter
   --avoid=mbuiterf
+  --avoid=mbrlen-tests
   --avoid=mbrtowc-tests
   --avoid=update-copyright-tests
 '
diff --git a/configure.ac b/configure.ac
index 3d630a2..0bc492c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,7 @@ PKG_PROG_PKG_CONFIG([0.9.0])
 # so don't worry about this common bug,
 # as working around it would merely slow grep down.
 gl_cv_func_mbrtowc_empty_input='assume yes'
+gl_cv_func_mbrlen_empty_input='assume yes'
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 gl_INIT
-- 
2.34.1

Reply via email to