diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-04 02:27:14 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-04 02:27:14 +0100 |
commit | 3c6d3052d3597100e9d531df03cb15e9988dc94d (patch) | |
tree | 4ad648a42698befd049fcc95167731fff428d099 /src/shared/utf8.c | |
parent | 3f18c60b2e09d1191ffede3aeabd967b57a1f918 (diff) |
utf8: when escaping unprintable unichars, escape the whole unichar, not just the first byte of it
Diffstat (limited to 'src/shared/utf8.c')
-rw-r--r-- | src/shared/utf8.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/shared/utf8.c b/src/shared/utf8.c index 0b6c38ebbf..699682010e 100644 --- a/src/shared/utf8.c +++ b/src/shared/utf8.c @@ -202,7 +202,7 @@ char *utf8_escape_invalid(const char *str) { s = mempcpy(s, str, len); str += len; } else { - s = mempcpy(s, UTF8_REPLACEMENT_CHARACTER, strlen(UTF8_REPLACEMENT_CHARACTER)); + s = stpcpy(s, UTF8_REPLACEMENT_CHARACTER); str += 1; } } @@ -230,18 +230,18 @@ char *utf8_escape_non_printable(const char *str) { s = mempcpy(s, str, len); str += len; } else { - if ((*str < ' ') || (*str >= 127)) { + while (len > 0) { *(s++) = '\\'; *(s++) = 'x'; *(s++) = hexchar((int) *str >> 4); *(s++) = hexchar((int) *str); - } else - *(s++) = *str; - str += 1; + str += 1; + len --; + } } } else { - s = mempcpy(s, UTF8_REPLACEMENT_CHARACTER, strlen(UTF8_REPLACEMENT_CHARACTER)); + s = stpcpy(s, UTF8_REPLACEMENT_CHARACTER); str += 1; } } |