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         | 3 ++-
 tests/od/od-N.sh | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/od.c b/src/od.c
index e749a6b08..265e3d2ee 100644
--- 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);
diff --git a/tests/od/od-N.sh b/tests/od/od-N.sh
index 40d3d914e..97c1a8f46 100755
--- a/tests/od/od-N.sh
+++ b/tests/od/od-N.sh
@@ -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
-- 
2.53.0


Reply via email to