]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
od: suppress address output on read error
authorPádraig Brady <P@draigBrady.com>
Wed, 25 Mar 2026 17:33:47 +0000 (17:33 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 25 Mar 2026 17:46:37 +0000 (17:46 +0000)
We don't output an address for `od missing` or `od --strings .`,
so be consistent and suppress the address for `od .`.

* src/od.c (dump): Only output an address if no errors
or the offset is non zero.

src/od.c
tests/od/od-N.sh

index e749a6b08698bcaafe651be39f09195fa09ebbf4..265e3d2ee8ab8de4a967a982503354c920a8ecc0 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -1561,7 +1561,8 @@ dump (void)
       current_offset += n_bytes_read;
     }
 
-  format_address (current_offset, '\n');
+  if (ok || current_offset)
+    format_address (current_offset, '\n');
 
   if (0 <= end_offset && end_offset <= current_offset)
     ok &= check_and_close (0);
index 40d3d914e391909430b2cea5c68da6a5f6c47d9f..97c1a8f466691f549c4828f0d08e49ec178fbaf3 100755 (executable)
@@ -54,4 +54,11 @@ printf '\001%10s\000%10s\000' | od -S10 > out || fail=1
 printf '%07o %10s\n' 1 '' 12 '' > exp || framework_failure_
 compare exp out || fail=1
 
+# Ensure no address output for read error
+# (Users may use -N0 -j... to do base conversion)
+if ! cat . >/dev/null 2>&1; then
+  returns_ 1 od -N1 . > out || fail=1
+  compare /dev/null out || fail=1
+fi
+
 Exit $fail