This is Karel Zak's patch to fix handling of (illegal) multi-byte chars. * mutt_wstr_trunc() does not reset mbrtowc() after error
* mutt_wstr_trunc() compare signed and unsigned numbers to check for maxlen and maxwid limits and does not care about unprintable chars Addresses: https://github.com/karelzak/mutt-kz/issues/58 Signed-off-by: Karel Zak <[email protected]> --- diff -urN mutt/curs_lib.c mutt.fix/curs_lib.c --- mutt/curs_lib.c 2016-03-17 23:22:15.547234169 +0000 +++ mutt.fix/curs_lib.c 2016-03-17 23:16:42.994127967 +0000 @@ -964,8 +964,10 @@ memset (&mbstate, 0, sizeof (mbstate)); for (w = 0; n && (cl = mbrtowc (&wc, src, n, &mbstate)); src += cl, n -= cl) { - if (cl == (size_t)(-1) || cl == (size_t)(-2)) + if (cl == (size_t)(-1) || cl == (size_t)(-2)) { cw = cl = 1; + memset(&mbstate, 0, sizeof (mbstate)); + } else { cw = wcwidth (wc); @@ -973,6 +975,8 @@ * until rendered by print_enriched_string (#3364) */ if (cw < 0 && cl == 1 && src[0] && src[0] < M_TREE_MAX) cw = 1; + else if (cw < 0) + cw = 0; /* unprintable wchar */ } if (cl + l > maxlen || cw + w > maxwid) break;
