[hackers] [sbase] Properly handle partial chunks in od(1) || FRIGN
commit 1eff1e8214568e68dcd97b71adcdb0626d77407d
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Oct 26 12:29:02 2015 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Oct 26 11:55:41 2015 +0000
Properly handle partial chunks in od(1)
Grab the remaining bytes and fill them up with zeroes in a
temporary buffer.
diff --git a/od.c b/od.c
index 0bd8f6c..0c361e2 100644
--- a/od.c
+++ b/od.c
_AT_@ -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;
_AT_@ -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))
Received on Mon Oct 26 2015 - 12:55:51 CET
This archive was generated by hypermail 2.3.0
: Mon Oct 26 2015 - 13:00:29 CET