Skip to content

Commit c4a908e

Browse files
committed
patch 7.4.2347
Problem: Crash when closing a buffer while Visual mode is active. (Dominique Pelle) Solution: Adjust the position before computing the number of lines. When closing the current buffer stop Visual mode.
1 parent abd468e commit c4a908e

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/buffer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ close_buffer(
578578
if (buf->b_ffname == NULL)
579579
del_buf = TRUE;
580580

581+
/* When closing the current buffer stop Visual mode before freeing
582+
* anything. */
583+
if (buf == curbuf)
584+
end_visual_mode();
585+
581586
/*
582587
* Free all things allocated for this buffer.
583588
* Also calls the "BufDelete" autocommands when del_buf is TRUE.
@@ -1379,6 +1384,10 @@ do_buffer(
13791384
}
13801385
}
13811386

1387+
/* When closing the current buffer stop Visual mode. */
1388+
if (buf == curbuf)
1389+
end_visual_mode();
1390+
13821391
/*
13831392
* If deleting the last (listed) buffer, make it empty.
13841393
* The last (listed) buffer cannot be unloaded.

src/normal.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
16091609
oap->start = curwin->w_cursor;
16101610
}
16111611

1612+
/* Just in case lines were deleted that make the position invalid. */
1613+
check_pos(curwin->w_buffer, &oap->end);
16121614
oap->line_count = oap->end.lnum - oap->start.lnum + 1;
16131615

16141616
#ifdef FEAT_VIRTUALEDIT
@@ -9451,10 +9453,7 @@ get_op_vcol(
94519453
#ifdef FEAT_MBYTE
94529454
/* prevent from moving onto a trail byte */
94539455
if (has_mbyte)
9454-
{
9455-
check_pos(curwin->w_buffer, &oap->end);
94569456
mb_adjustpos(curwin->w_buffer, &oap->end);
9457-
}
94589457
#endif
94599458

94609459
getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol);

src/testdir/test_normal.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,3 +1998,17 @@ func! Test_normal46_ignore()
19981998
" clean up
19991999
bw!
20002000
endfu
2001+
2002+
func! Test_normal47_visual_buf_wipe()
2003+
" This was causing a crash or ml_get error.
2004+
enew!
2005+
call setline(1,'xxx')
2006+
normal $
2007+
new
2008+
call setline(1, range(1,2))
2009+
2
2010+
exe "norm \<C-V>$"
2011+
bw!
2012+
norm yp
2013+
set nomodified
2014+
endfu

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2347,
766768
/**/
767769
2346,
768770
/**/

0 commit comments

Comments
 (0)