Thanks for the bug report, test case and fix. I installed the attached,
which fixes the bug in a different way to be portable to platforms where
off_t is narrower than intmax_t.
>From 3f11e21091a88937908d067dd800ad678e39abcb Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 1 Oct 2019 11:08:30 -0700
Subject: [PATCH 1/2] cmp: fix -l width bug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Dave Odell (Bug#37558).
* src/cmp.c (cmp): Treat negative ‘bytes’ as infinite, fixing a
bug introduced in the 2019-08-27 patch that fixed Bug#35256.
---
src/cmp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/cmp.c b/src/cmp.c
index 16e8869..5152ca0 100644
--- a/src/cmp.c
+++ b/src/cmp.c
@@ -394,7 +394,8 @@ cmp (void)
if (comparison_type == type_all_diffs)
{
- off_t byte_number_max = MIN (bytes, TYPE_MAXIMUM (off_t));
+ off_t byte_number_max = (0 <= bytes && bytes <= TYPE_MAXIMUM (off_t)
+ ? bytes : TYPE_MAXIMUM (off_t));
for (f = 0; f < 2; f++)
if (S_ISREG (stat_buf[f].st_mode))
--
2.21.0
>From 845e03a2c1d5fa137b4df33e048b008b7b6c3153 Mon Sep 17 00:00:00 2001
From: Dave Odell <dmo2...@gmail.com>
Date: Tue, 1 Oct 2019 11:09:15 -0700
Subject: [PATCH 2/2] cmp: add test case for Bug#37558
* tests/cmp: New test case (Bug#37558).
Copyright-paperwork-exempt: yes
---
tests/cmp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tests/cmp b/tests/cmp
index 97f2b5f..ff49388 100755
--- a/tests/cmp
+++ b/tests/cmp
@@ -218,4 +218,14 @@ case `LC_ALL=C cmp -b bad bug` in
*) echo 'expected cmp -b to report a and u'; fail=1;;
esac
+printf 'Jackdaws love my big sphinx of quartz!' > j1
+printf 'jackdaws love my big sphinx of quartz.' > j2
+cat <<'EOF' > exp2 || fail=1
+ 1 112 J 152 j
+38 41 ! 56 .
+EOF
+cmp -bl j1 j2 > out2
+test $? -eq 1 || fail=1
+compare exp2 out2 || fail=1
+
Exit $fail
--
2.21.0