From 99ab4bae75221e9605c5906f18fef3f732ef5ac6 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 27 Feb 2017 15:42:49 +0000 Subject: [PATCH] shell: fix printing hex when size is larger than 16 --- shell.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shell.c b/shell.c index ed0638c..accd327 100644 --- a/shell.c +++ b/shell.c @@ -57,19 +57,21 @@ static void parse_hex(FILE *fp, char *buf, size_t len) static void print_hex_ascii(FILE *fp, const char *buf, size_t len) { - size_t i, j; + size_t n, i; char c; - for (j = 0; j < len; j += 16, buf += 16) { + for (; len; buf += n, len -= n) { + n = min(len, 16); + for (i = 0; i < 16; ++i) { - c = (i < len) ? buf[i] : 0; + c = (i < n) ? buf[i] : 0; fprintf(fp, "%02x", c); } fprintf(fp, " "); for (i = 0; i < 16; ++i) { - c = (i < len) ? buf[i] : 0; + c = (i < n) ? buf[i] : 0; fprintf(fp, "%c", isalnum(c) ? c : '.'); }