chars: a control character can never be an invalid multibyte sequence

The function is_cntrl_mbchar() has always been called successfully before
calling control_mbrep(), so the passed character *is* a valid sequence.
master
Benno Schulenberg 2016-05-30 12:52:00 +02:00
parent 21d9bd1107
commit 05e2a6d259
1 changed files with 3 additions and 15 deletions

View File

@ -250,9 +250,7 @@ wchar_t control_wrep(wchar_t wc)
#endif #endif
/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch], /* c is a multibyte control character. It displays as ^@, ^?, or ^[ch],
* where ch is (c + 64). We return that multibyte character. If crep * where ch is (c + 64). We return that multibyte character. */
* is an invalid multibyte sequence, it will be replaced with Unicode
* 0xFFFD (Replacement Character). */
char *control_mbrep(const char *c, char *crep, int *crep_len) char *control_mbrep(const char *c, char *crep, int *crep_len)
{ {
assert(c != NULL && crep != NULL && crep_len != NULL); assert(c != NULL && crep != NULL && crep_len != NULL);
@ -261,18 +259,8 @@ char *control_mbrep(const char *c, char *crep, int *crep_len)
if (use_utf8) { if (use_utf8) {
wchar_t wc; wchar_t wc;
if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { IGNORE_CALL_RESULT(mbtowc(&wc, c, MB_CUR_MAX));
mbtowc_reset(); *crep_len = wctomb(crep, control_wrep(wc));
*crep_len = bad_mbchar_len;
strncpy(crep, bad_mbchar, *crep_len);
} else {
*crep_len = wctomb(crep, control_wrep(wc));
if (*crep_len < 0) {
wctomb_reset();
*crep_len = 0;
}
}
} else } else
#endif #endif
{ {