From 782bdd3b64fb9df191a225e22cd8ce96d9410338 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 1 May 2017 23:58:58 +0300 Subject: dump.c: Align to_hex to at least 2 chars This is to have nice aligned output when outputting byte arrays for example. --- src/dump.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-70-g09d2