Skip to content

Commit 5a067d2

Browse files
committed
Fix for UTF-8 problems with the ascii printer.
Characters need to be in the ascii range, otherwise invalid UTF-8 data can (and is) written. So anything outside the 32-126 range is output as hexadecimal number. Signed-off-by: Hans Dijkema <[email protected]>
1 parent ddccf49 commit 5a067d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/webui.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8848,10 +8848,16 @@ static void _webui_print_hex(const char* data, size_t len) {
88488848
}
88498849
static void _webui_print_ascii(const char* data, size_t len) {
88508850
for (size_t i = 0; i < len; i++) {
8851-
if ((unsigned char)* data == 0x00)
8852-
_webui_log_debug("%c", 0xCF);
8853-
else
8854-
_webui_log_debug("%c", (unsigned char)* data);
8851+
if ((unsigned char)* data == 0x00) {
8852+
_webui_log_debug("0x%02X", 0xCF);
8853+
} else {
8854+
register unsigned char c = (unsigned char)* data;
8855+
if (c < 32 || c > 126) {
8856+
_webui_log_debug("0x%02X", c);
8857+
} else {
8858+
_webui_log_debug("%c", c);
8859+
}
8860+
}
88558861
data++;
88568862
}
88578863
}

0 commit comments

Comments
 (0)