summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-05-01 23:58:58 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2017-05-01 23:58:58 +0300
commit782bdd3b64fb9df191a225e22cd8ce96d9410338 (patch)
treebb130d154c87c1e76515af6fc99a0ca71324bd5e /src
parent53cabb8906f69c2fcecaeb36d18d41c61bc3e85a (diff)
dump.c: Align to_hex to at least 2 chars
This is to have nice aligned output when outputting byte arrays for example.
Diffstat (limited to 'src')
-rw-r--r--src/dump.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/dump.c b/src/dump.c
index 8634b72..ef83b34 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -31,20 +31,17 @@ to_hex(const uint8_t *buf, const size_t buf_sz, char *out, const size_t out_sz,
const uint8_t hi = (buf[idx] >> (4 * (c + 1))) & nbs;
const uint8_t lo = (buf[idx] >> (8 * c)) & nbs;
- if (w || hi) {
+ if (w || hi || lo) {
out[w++] = nibble[hi];
- last_non_zero = (hi ? w : last_non_zero);
- }
-
- if (w || lo) {
out[w++] = nibble[lo];
- last_non_zero = (lo ? w : last_non_zero);
+ last_non_zero = (hi || lo ? w : last_non_zero);
}
}
}
if (!w) {
out[w++] = nibble[0];
+ out[w++] = nibble[0];
} else {
w = last_non_zero;
}