* Convert a UTF-8 byte sequence to a wide character.
* If the sequence is illegal or truncated by a NUL the first byte is
* returned.
+ * For an overlong sequence this may return zero.
* Does not include composing characters, of course.
*/
int
)
{
p = ml_get_buf(buf, lp->lnum, FALSE);
- lp->col -= (*mb_head_off)(p, p + lp->col);
+ if (*p == NUL || (int)STRLEN(p) < lp->col)
+ lp->col = 0;
+ else
+ lp->col -= (*mb_head_off)(p, p + lp->col);
#ifdef FEAT_VIRTUALEDIT
/* Reset "coladd" when the cursor would be on the right half of a
* double-wide character. */