od: suppress address output on read error

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.
This commit is contained in:
Pádraig Brady
2026-03-25 17:33:47 +00:00
parent cc3dd92f84
commit 0ec2340c08
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -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);
+7
View File
@@ -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