From 14b27726d4fa05d7d18dcc8711d50f63e67571f3 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Thu, 14 Jul 2022 17:16:30 +0100 Subject: [PATCH] Protect terminal dump from vagaries of C libray implementation of isalpha() etc Some C libraries assign true to isalpha(0xff), isdigit(0xff) or ispunct(0xff), which means that the Operating System terminal sees a character 0xff which it may not have a useful display character for. This commit only outputs printable ASCII characters for an AVRDUDE terminal dump reducing the risk of the OS terminal not being able to print the character properly. --- src/term.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/term.c b/src/term.c index 52906f29..7fe6246c 100644 --- a/src/term.c +++ b/src/term.c @@ -198,13 +198,9 @@ static int chardump_line(char * buffer, unsigned char * p, int n, int pad) n = n < 1? 1: n > sizeof b? sizeof b: n; memcpy(b, p, n); - for (int i = 0; i < n; i++) { - buffer[i] = '.'; - if (isalpha(b[i]) || isdigit(b[i]) || ispunct(b[i])) - buffer[i] = b[i]; - else if (isspace(b[i])) - buffer[i] = ' '; - } + for (int i = 0; i < n; i++) + buffer[i] = isascii(b[i]) && isspace(b[i])? ' ': + isascii(b[i]) && isgraph(b[i])? b[i]: '.'; for (i = n; i < pad; i++) buffer[i] = ' ';