summaryrefslogtreecommitdiff
path: root/src/od.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-07-07 04:46:03 +0000
committerJim Meyering <jim@meyering.net>1995-07-07 04:46:03 +0000
commit67718aff76c90766c1167612f790e7aa655ff941 (patch)
tree5aad5019149a6d05e948f4feed170ce666d9377b /src/od.c
parentb9d3dc410149360b14936764c52b327c785296fa (diff)
downloadcoreutils-67718aff76c90766c1167612f790e7aa655ff941.tar.xz
(dump): Correct loop-termination criterion.
Before, running `printf 1234| ./od --width=4 --read-bytes=4' printed output for 8 bytes -- the last four were garbage. This happened only when the dump limit, N, was specified (with --read-bytes=N) and N was a multiple of bytes_per_block (usually 16, but 4 in this example). From Andreas Schwab.
Diffstat (limited to 'src/od.c')
-rw-r--r--src/od.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/od.c b/src/od.c
index ffce0d6a0..28fdc66d4 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1397,12 +1397,16 @@ dump ()
{
end_offset = n_bytes_to_skip + max_bytes_to_format;
- n_bytes_read = 0;
- while (current_offset < end_offset)
+ while (1)
{
size_t n_needed;
n_needed = MIN (end_offset - current_offset,
(off_t) bytes_per_block);
+ if (n_needed == 0)
+ {
+ n_bytes_read = 0;
+ break;
+ }
err |= read_block (n_needed, block[idx], &n_bytes_read);
if (n_bytes_read < bytes_per_block)
break;