From ce50cc6d5fad3bbb48d6ce16a06cdf40637ec89f Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 27 Feb 2017 15:36:57 +0000 Subject: [PATCH] shell: print zeroes when the buffer size is not a multiple of 16 --- shell.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell.c b/shell.c index 194a663..ed0638c 100644 --- a/shell.c +++ b/shell.c @@ -62,13 +62,14 @@ static void print_hex_ascii(FILE *fp, const char *buf, size_t len) for (j = 0; j < len; j += 16, buf += 16) { for (i = 0; i < 16; ++i) { - fprintf(fp, "%02x", buf[i]); + c = (i < len) ? buf[i] : 0; + fprintf(fp, "%02x", c); } fprintf(fp, " "); for (i = 0; i < 16; ++i) { - c = buf[i]; + c = (i < len) ? buf[i] : 0; fprintf(fp, "%c", isalnum(c) ? c : '.'); }