From 93be2ba5422cf08369269fe12567dea04254aa20 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 9 Apr 2018 01:12:52 +0300 Subject: [PATCH] charset: Fix transchar() with multibyte characters It appears that transchar() was working under assumption that `transchar_nonprint()` may be used for multibyte characters while its documentation stated exact opposite. It was not actually untrue though, except that longer buffer would be needed then the one stated in documentation. But it is false now with assert(). --- src/nvim/charset.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index d8d080ee8a..aecde29ce2 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -517,14 +517,16 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) // Does NOT work for multi-byte characters, c must be <= 255. // Also doesn't work for the first byte of a multi-byte, "c" must be a // character! -static char_u transchar_buf[7]; +static char_u transchar_buf[11]; -/// Translates a character +/// Translate a character into a printable one, leaving printable ASCII intact /// -/// @param c +/// All unicode characters are considered non-printable in this function. /// -/// @return translated character. -char_u* transchar(int c) +/// @param[in] c Character to translate. +/// +/// @return translated character into a static buffer. +char_u *transchar(int c) { int i = 0; if (IS_SPECIAL(c)) { @@ -537,12 +539,14 @@ char_u* transchar(int c) if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || (p_altkeymap && F_ischar(c)))) - || ((c < 256) && vim_isprintc_strict(c))) { + || ((c <= 0xFF) && vim_isprintc_strict(c))) { // printable character transchar_buf[i] = (char_u)c; transchar_buf[i + 1] = NUL; - } else { + } else if (c <= 0xFF){ transchar_nonprint(transchar_buf + i, c); + } else { + transchar_hex((char *)transchar_buf + i, c); } return transchar_buf; }