1
0

proj/intercept.c: Fix non-ASCII character escaping

This commit is contained in:
2025-04-14 19:28:51 +02:00
parent e851f5b90d
commit cd8384f4fb

View File

@@ -546,10 +546,10 @@ static uint8_t func_flags[256];
static size_t msg_bytes(char *buf, size_t maxlen, size_t len, const char *str, int flags) {
size_t offset = flags & 1 ? snprintf(buf, maxlen, "\"") : snprintf(buf, maxlen, "%p:\"", str);
for (int i = 0; i < len && offset <= maxlen - 2; i++) {
char ch = str[i];
const uint8_t ch = str[i];
if (ch == '\\' || ch == '"') {
buf[offset++] = '\\';
buf[offset++] = ch;
buf[offset++] = (char)ch;
} else if (ch == '\t') {
buf[offset++] = '\\';
buf[offset++] = 't';
@@ -559,10 +559,10 @@ static size_t msg_bytes(char *buf, size_t maxlen, size_t len, const char *str, i
} else if (ch == '\r') {
buf[offset++] = '\\';
buf[offset++] = 'r';
} else if ((ch >= 0 && ch < 0x20) || ch == 0x7F) {
} else if (ch < 0x20 || ch >= 0x7F) {
offset += snprintf(buf + offset, maxlen - offset, "\\x%02x", ch);
} else {
buf[offset++] = ch;
buf[offset++] = (char)ch;
}
}
if (offset <= maxlen - 2) {