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().
This commit is contained in:
ZyX
2018-04-09 01:12:52 +03:00
parent 58a5699a44
commit 93be2ba542

View File

@@ -517,13 +517,15 @@ 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. // 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 // Also doesn't work for the first byte of a multi-byte, "c" must be a
// character! // 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. /// @param[in] c Character to translate.
///
/// @return translated character into a static buffer.
char_u *transchar(int c) char_u *transchar(int c)
{ {
int i = 0; int i = 0;
@@ -537,12 +539,14 @@ char_u* transchar(int c)
if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) if ((!chartab_initialized && (((c >= ' ') && (c <= '~'))
|| (p_altkeymap && F_ischar(c)))) || (p_altkeymap && F_ischar(c))))
|| ((c < 256) && vim_isprintc_strict(c))) { || ((c <= 0xFF) && vim_isprintc_strict(c))) {
// printable character // printable character
transchar_buf[i] = (char_u)c; transchar_buf[i] = (char_u)c;
transchar_buf[i + 1] = NUL; transchar_buf[i + 1] = NUL;
} else { } else if (c <= 0xFF){
transchar_nonprint(transchar_buf + i, c); transchar_nonprint(transchar_buf + i, c);
} else {
transchar_hex((char *)transchar_buf + i, c);
} }
return transchar_buf; return transchar_buf;
} }