Properly handle partial chunks in od(1)
Grab the remaining bytes and fill them up with zeroes in a temporary buffer.
This commit is contained in:
parent
914991f5f6
commit
1eff1e8214
16
od.c
16
od.c
|
@ -93,6 +93,7 @@ printline(unsigned char *line, size_t len, off_t addr)
|
||||||
struct type *t = NULL;
|
struct type *t = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int first = 1;
|
int first = 1;
|
||||||
|
unsigned char *tmp;
|
||||||
|
|
||||||
if (TAILQ_EMPTY(&head))
|
if (TAILQ_EMPTY(&head))
|
||||||
goto once;
|
goto once;
|
||||||
|
@ -104,10 +105,17 @@ once:
|
||||||
} else {
|
} else {
|
||||||
printf("%*c", (addr_format == 'n') ? 1 : 7, ' ');
|
printf("%*c", (addr_format == 'n') ? 1 : 7, ' ');
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; ) {
|
for (i = 0; i < len; i += MIN(len - i, t ? t->len : 4)) {
|
||||||
printchunk(line + i, t ? t->format : 'o',
|
if (len - i < (t ? t->len : 4)) {
|
||||||
MIN(len - i, t ? t->len : 4));
|
tmp = ecalloc(t ? t->len : 4, 1);
|
||||||
i += MIN(len - i, t ? t->len : 4);
|
memcpy(tmp, line + i, len - i);
|
||||||
|
printchunk(tmp, t ? t->format : 'o',
|
||||||
|
t ? t->len : 4);
|
||||||
|
free(tmp);
|
||||||
|
} else {
|
||||||
|
printchunk(line + i, t ? t->format : 'o',
|
||||||
|
t ? t->len : 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputc('\n', stdout);
|
fputc('\n', stdout);
|
||||||
if (TAILQ_EMPTY(&head) || (!len && !first))
|
if (TAILQ_EMPTY(&head) || (!len && !first))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user