logging: Fix signed integer cast for isprint

Casting the value byte to char may result in it being a negative
number. On some platforms this could lead to either UB, or a crash.

Signed-off-by: Dennis Sitelew <dennis.sitelew@grandcentrix.net>
This commit is contained in:
Dennis Sitelew 2022-09-09 12:41:32 +02:00 committed by Fabio Baltieri
commit 42f9b69f50
2 changed files with 2 additions and 2 deletions

View file

@ -390,7 +390,7 @@ static void hexdump_line_print(const struct log_output *output,
}
if (i < length) {
char c = (char)data[i];
unsigned char c = (unsigned char)data[i];
print_formatted(output, "%c",
isprint((int)c) ? c : '.');

View file

@ -582,7 +582,7 @@ static void hexdump_line_print(const uint8_t *data, uint32_t length,
}
if (i < length) {
char c = (char)data[i];
unsigned char c = (unsigned char)data[i];
*buf = isprint((int)c) ? c : '.';
} else {