sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 4b4ffac872b870db6445f07e736c357e2e55b9e7
parent 9ee8151943804d5b6159c97f4543c78e6065e18b
Author: FRIGN <dev@frign.de>
Date:   Mon Oct 26 12:29:02 +0100

Properly handle partial chunks in od(1)

Grab the remaining bytes and fill them up with zeroes in a
temporary buffer.

Diffstat:
od.c | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/od.c b/od.c @@ -93,6 +93,7 @@ printline(unsigned char *line, size_t len, off_t addr) struct type *t = NULL; size_t i; int first = 1; + unsigned char *tmp; if (TAILQ_EMPTY(&head)) goto once; @@ -104,10 +105,17 @@ once: } else { printf("%*c", (addr_format == 'n') ? 1 : 7, ' '); } - for (i = 0; i < len; ) { - printchunk(line + i, t ? t->format : 'o', - MIN(len - i, t ? t->len : 4)); - i += MIN(len - i, t ? t->len : 4); + for (i = 0; i < len; i += MIN(len - i, t ? t->len : 4)) { + if (len - i < (t ? t->len : 4)) { + tmp = ecalloc(t ? t->len : 4, 1); + 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); if (TAILQ_EMPTY(&head) || (!len && !first))