Skip to content

Commit 941c12d

Browse files
committed
patch 8.0.0234: crash when using put in Visual mode
Problem: When several lines are visually selected and one of them is short, using put may cause a crash. (Axel Bender) Solution: Check for a short line. (Christian Brabandt)
1 parent bff6ad1 commit 941c12d

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/ops.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,16 +3774,25 @@ do_put(
37743774
*/
37753775
if (y_type == MCHAR && y_size == 1)
37763776
{
3777-
linenr_T end = curbuf->b_visual.vi_end.lnum;
3777+
linenr_T end;
37783778

3779-
if (curbuf->b_visual.vi_end.lnum < curbuf->b_visual.vi_start.lnum)
3780-
end = curbuf->b_visual.vi_start.lnum;
3779+
if (VIsual_active)
3780+
{
3781+
end = curbuf->b_visual.vi_end.lnum;
3782+
if (end < curbuf->b_visual.vi_start.lnum)
3783+
end = curbuf->b_visual.vi_start.lnum;
3784+
}
37813785

37823786
do {
37833787
totlen = count * yanklen;
37843788
if (totlen > 0)
37853789
{
37863790
oldp = ml_get(lnum);
3791+
if (VIsual_active && col > (int)STRLEN(oldp))
3792+
{
3793+
lnum++;
3794+
continue;
3795+
}
37873796
newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1));
37883797
if (newp == NULL)
37893798
goto end; /* alloc() gave an error message */

src/testdir/test_put.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ func Test_put_char_block()
2121
call assert_equal(['Xfile_put 1', 'Xfile_put 2'], getline(1,2))
2222
bw!
2323
endfunc
24+
25+
func Test_put_char_block2()
26+
new
27+
let a = [ getreg('a'), getregtype('a') ]
28+
call setreg('a', ' one ', 'v')
29+
call setline(1, ['Line 1', '', 'Line 3', ''])
30+
" visually select the first 3 lines and put register a over it
31+
exe "norm! ggl\<c-v>2j2l\"ap"
32+
call assert_equal(['L one 1', '', 'L one 3', ''], getline(1,4))
33+
" clean up
34+
bw!
35+
call setreg('a', a[0], a[1])
36+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
234,
767769
/**/
768770
233,
769771
/**/

0 commit comments

Comments
 (0)