there is an encoding error and mbrtowc returns (size_t)(-1) no value
should be stored in *pwc (the first argument), as I understand it, but
here mbrtowc is storing 8 when presented with the bytes "\xc8\x4d".
However, relying on mbrtowc not to store anything in *pwc when there
is an error is a bit silly; it makes sense to look at the return
value. So, the following patch should be applied if Pawel can confirm
that it fixes the problem. I've tested it and it worked for me with
glibc's mbrtowc.
while ((wc1 = 0, mbstate1 = mbstate,
k1 = k + mbrtowc (&wc1, (char *)buf+ch+k, cnt-ch-k, &mbstate1),
- wc1 == '\b') &&
+ k1 - k > 0 && wc1 == '\b') &&
(wc1 = 0,
k2 = mbrtowc (&wc1, (char *)buf+ch+k1, cnt-ch-k1, &mbstate1),
- IsWPrint (wc1)))
+ k2 > 0 && IsWPrint (wc1)))
{
if (wc == wc1)
{