Subject: Re: bug#79414: the ratio output by "gzip -l" is less than 0

From: Paul Eggert <[email-masked]>
Date: Tue, 9 Sep 2025 11:40:43 -0700

On 2025-09-09 11:12, Adler, Mark wrote:
> pigz reports "-inf%”. Alas, a lower-case “i”.

Thanks, good suggestion, I installed the attached into gzip.

From 131964d8ffbeeff75bd5372b4e231290e9b12be7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 9 Sep 2025 11:33:08 -0700
Subject: [PATCH] gzip: report "-Inf%" for negative infinity

* tests/list: Test for this.
* util.c (display_ratio):
Say "-%Inf%" if the compression ratio is negative infinity.
From a suggestion by Mark Adler <https://bugs.gnu.org/79414#13>.
---
 NEWS       | 5 +++++
 tests/list | 8 ++++++++
 util.c     | 5 ++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index b480dea..0642167 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,11 @@ GNU gzip NEWS                                    -*- outline -*-
   A use of uninitialized memory on some malformed inputs has been fixed.
   [bug present since the beginning]
 
+** Changes in behavior
+
+  gzip -l now reports "-Inf%" instead of "0.0%" for the infinite
+  compression ratio of an empty file.
+
 
 * Noteworthy changes in release 1.14 (2025-04-09) [stable]
 
diff --git a/tests/list b/tests/list
index 7fadc12..005e62c 100755
--- a/tests/list
+++ b/tests/list
@@ -28,6 +28,14 @@ gzip -l in.gz >out1 || fail=1
 gzip -l in.gz | cat >out2 || fail=1
 compare out1 out2 || fail=1
 
+: >empty || framework_failure_
+gzip empty || fail=1
+gzip -l empty.gz >emptyout || fail=1
+case $(cat emptyout) in
+  *' -Inf% '*) ;;
+  *) cat smallout; fail=1;;
+esac
+
 echo '' >small || framework_failure_
 gzip small || fail=1
 cat small.gz small.gz >smallx2.gz || framework_failure_
diff --git a/util.c b/util.c
index bbec0f4..5453cd6 100644
--- a/util.c
+++ b/util.c
@@ -402,5 +402,8 @@ void write_error()
 void
 display_ratio (off_t num, off_t den, FILE *file)
 {
-    fprintf(file, "%5.1f%%", den == 0 ? 0 : 100.0 * num / den);
+  if (den)
+    fprintf (file, "%5.1f%%", 100.0 * num / den);
+  else
+    fputs (" -Inf%", file);
 }
-- 
2.48.1