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.
This commit is contained in:
Stefan Rueger 2022-07-14 17:16:30 +01:00
parent 5721908e63
commit 14b27726d4
1 changed files with 3 additions and 7 deletions

View File

@ -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] = ' ';