proj/intercept.c: Fix non-ASCII character escaping
This commit is contained in:
@@ -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) {
|
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);
|
size_t offset = flags & 1 ? snprintf(buf, maxlen, "\"") : snprintf(buf, maxlen, "%p:\"", str);
|
||||||
for (int i = 0; i < len && offset <= maxlen - 2; i++) {
|
for (int i = 0; i < len && offset <= maxlen - 2; i++) {
|
||||||
char ch = str[i];
|
const uint8_t ch = str[i];
|
||||||
if (ch == '\\' || ch == '"') {
|
if (ch == '\\' || ch == '"') {
|
||||||
buf[offset++] = '\\';
|
buf[offset++] = '\\';
|
||||||
buf[offset++] = ch;
|
buf[offset++] = (char)ch;
|
||||||
} else if (ch == '\t') {
|
} else if (ch == '\t') {
|
||||||
buf[offset++] = '\\';
|
buf[offset++] = '\\';
|
||||||
buf[offset++] = 't';
|
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') {
|
} else if (ch == '\r') {
|
||||||
buf[offset++] = '\\';
|
buf[offset++] = '\\';
|
||||||
buf[offset++] = 'r';
|
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);
|
offset += snprintf(buf + offset, maxlen - offset, "\\x%02x", ch);
|
||||||
} else {
|
} else {
|
||||||
buf[offset++] = ch;
|
buf[offset++] = (char)ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (offset <= maxlen - 2) {
|
if (offset <= maxlen - 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user