Skip to content

Commit df098fe

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.1048: crash after scrolling and pasting in silent Ex mode
Problem: Crash after scrolling and pasting in silent Ex mode. (fizz-is-on-the-way) Solution: Don't move cursor to line 0 when scrolling. (zeertzjq) closes: #16506 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 613d0bc commit df098fe

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/move.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3285,8 +3285,11 @@ pagescroll(int dir, long count, int half)
32853285
{
32863286
// Place cursor at top or bottom of window.
32873287
validate_botline();
3288-
curwin->w_cursor.lnum = (dir == FORWARD ? curwin->w_topline
3288+
linenr_T lnum = (dir == FORWARD ? curwin->w_topline
32893289
: curwin->w_botline - 1);
3290+
// In silent Ex mode the value of w_botline - 1 may be 0,
3291+
// but cursor lnum needs to be at least 1.
3292+
curwin->w_cursor.lnum = MAX(lnum, 1);
32903293
}
32913294
}
32923295

src/testdir/test_normal.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,22 @@ func Test_scroll_in_ex_mode()
13421342
call delete('Xdone')
13431343
endfunc
13441344

1345+
func Test_scroll_and_paste_in_ex_mode()
1346+
" This used to crash because of moving cursor to line 0.
1347+
let lines =<< trim END
1348+
v/foo/vi|YY9PYQ
1349+
v/bar/vi|YY9PYQ
1350+
v/bar/exe line('.') == 1 ? "vi|Y\<C-B>9PYQ" : "vi|YQ"
1351+
call writefile(['done'], 'Xdone')
1352+
qa!
1353+
END
1354+
call writefile(lines, 'Xscript', 'D')
1355+
call assert_equal(1, RunVim([], [], '-u NONE -i NONE -n -X -Z -e -s -S Xscript'))
1356+
call assert_equal(['done'], readfile('Xdone'))
1357+
1358+
call delete('Xdone')
1359+
endfunc
1360+
13451361
" Test for the 'sidescroll' option
13461362
func Test_sidescroll_opt()
13471363
new
@@ -4293,4 +4309,5 @@ func Test_normal_go()
42934309

42944310
bwipe!
42954311
endfunc
4312+
42964313
" vim: shiftwidth=2 sts=2 expandtab nofoldenable

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+
1048,
707709
/**/
708710
1047,
709711
/**/

0 commit comments

Comments
 (0)