// Put the '] mark on the first byte of the last inserted character.
// Correct the length for change in indent.
curbuf->b_op_end.lnum = new_lnum;
- col = (colnr_T)y_array[y_size - 1].length - lendiff;
+ col = MAX(0, (colnr_T)y_array[y_size - 1].length - lendiff);
if (col > 1)
{
curbuf->b_op_end.col = col - 1;
call setreg(1, a[0], a[1])
endfunc
+" this caused an illegal memory access and a crash
+func Test_register_cursor_column_negative()
+ CheckRunVimInTerminal
+ let script =<< trim END
+ f XREGISTER
+ call setline(1, 'abcdef a')
+ call setreg("a", "\n", 'c')
+ call cursor(1, 7)
+ call feedkeys("i\<C-R>\<C-P>azyx$#\<esc>", 't')
+ END
+ call writefile(script, 'XRegister123', 'D')
+ let buf = RunVimInTerminal('-S XRegister123', {})
+ call term_sendkeys(buf, "\<c-g>")
+ call WaitForAssert({-> assert_match('XREGISTER', term_getline(buf, 19))})
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab