Fix potential underflow of cursor position