Skip to content

Commit 95e18cc

Browse files
authored
Merge pull request #661 from hdijkema/ascii-logging
Fix for UTF-8 problems with the ascii printer.
2 parents ddccf49 + 1456940 commit 95e18cc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/webui.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8847,11 +8847,19 @@ static void _webui_print_hex(const char* data, size_t len) {
88478847
}
88488848
}
88498849
static void _webui_print_ascii(const char* data, size_t len) {
8850+
// This function is used to print the protocol binary packets. the packet
8851+
// may have ASCII and `0x00` inside text, as well as other non-ascii bytes
88508852
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);
8853+
register unsigned char c = (unsigned char)* data;
8854+
if (c == 0x00) {
8855+
_webui_log_debug("%c", 0xCF); // Print `¤` | TODO: Maybe we can simply print a blank space?
8856+
} else {
8857+
if (c < 32 || c > 126) {
8858+
_webui_log_debug("[0x%02X]", c);
8859+
} else {
8860+
_webui_log_debug("%c", c);
8861+
}
8862+
}
88558863
data++;
88568864
}
88578865
}

0 commit comments

Comments
 (0)