--- tcsh-6.14.00/sh.lex.c.wide-crash 2006-02-28 03:34:58.000000000 +0100 +++ tcsh-6.14.00/sh.lex.c 2006-02-28 03:35:31.000000000 +0100 @@ -1710,13 +1710,13 @@ break; partial += r; i = 0; - while (i < partial) { + while (i < partial && nchars != 0) { int len; len = normal_mbtowc(buf + res, cbuf + i, partial - i); if (len == -1) { reset_mbtowc(); - if (partial < MB_LEN_MAX && r > 0) + if (partial - i < MB_LEN_MAX && r > 0) /* Maybe a partial character and there is still a chance to read more */ break; @@ -1735,7 +1735,7 @@ if (i != partial) memmove(cbuf, cbuf + i, partial - i); partial -= i; - } while (partial != 0); + } while (partial != 0 && nchars != 0); /* Throwing away possible partial multibyte characters on error */ return res != 0 ? res : r; }