Skip to content

Commit e0029da

Browse files
committed
patch 9.1.1143: illegal memory access when putting a register
Problem: illegal memory access when putting a register Solution: make sure cursor column doesn't become negative Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 28155d0 commit e0029da

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/register.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ do_put(
22492249
// Put the '] mark on the first byte of the last inserted character.
22502250
// Correct the length for change in indent.
22512251
curbuf->b_op_end.lnum = new_lnum;
2252-
col = (colnr_T)y_array[y_size - 1].length - lendiff;
2252+
col = MAX(0, (colnr_T)y_array[y_size - 1].length - lendiff);
22532253
if (col > 1)
22542254
{
22552255
curbuf->b_op_end.col = col - 1;

src/testdir/test_registers.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,4 +1123,21 @@ func Test_register_redir_display()
11231123
call setreg(1, a[0], a[1])
11241124
endfunc
11251125

1126+
" this caused an illegal memory access and a crash
1127+
func Test_register_cursor_column_negative()
1128+
CheckRunVimInTerminal
1129+
let script =<< trim END
1130+
f XREGISTER
1131+
call setline(1, 'abcdef a')
1132+
call setreg("a", "\n", 'c')
1133+
call cursor(1, 7)
1134+
call feedkeys("i\<C-R>\<C-P>azyx$#\<esc>", 't')
1135+
END
1136+
call writefile(script, 'XRegister123', 'D')
1137+
let buf = RunVimInTerminal('-S XRegister123', {})
1138+
call term_sendkeys(buf, "\<c-g>")
1139+
call WaitForAssert({-> assert_match('XREGISTER', term_getline(buf, 19))})
1140+
call StopVimInTerminal(buf)
1141+
endfunc
1142+
11261143
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1143,
707709
/**/
708710
1142,
709711
/**/

0 commit comments

Comments
 (0)