From 42f9b69f50b70deef12260d71bd70544b005aa89 Mon Sep 17 00:00:00 2001 From: Dennis Sitelew Date: Fri, 9 Sep 2022 12:41:32 +0200 Subject: [PATCH] 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 --- subsys/logging/log_output.c | 2 +- subsys/logging/log_output_syst.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/logging/log_output.c b/subsys/logging/log_output.c index a5583e0c2f6..d07681dd0e0 100644 --- a/subsys/logging/log_output.c +++ b/subsys/logging/log_output.c @@ -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 : '.'); diff --git a/subsys/logging/log_output_syst.c b/subsys/logging/log_output_syst.c index a30189373c0..4fa22625b12 100644 --- a/subsys/logging/log_output_syst.c +++ b/subsys/logging/log_output_syst.c @@ -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 {