Skip to content

Commit 1aa5ca4

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.2055: Division by zero in :file after failing to wipe buffer
Problem: Division by zero in :file after failing to wipe buffer (after 8.2.4631). Solution: Still call buf_clear_file() when failing to wipe buffer (zeertzjq). closes: #19088 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 0ed8ba3 commit 1aa5ca4

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/buffer.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ close_buffer(
707707
// If the buffer was in curwin and the window has changed, go back to that
708708
// window, if it still exists. This avoids that ":edit x" triggering a
709709
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
710-
if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
710+
if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
711711
{
712712
block_autocmds();
713713
goto_tabpage_win(the_curtab, the_curwin);
@@ -782,16 +782,13 @@ close_buffer(
782782

783783
/*
784784
* Remove the buffer from the list.
785+
* Do not wipe out the buffer if it is used in a window.
785786
*/
786-
if (wipe_buf)
787+
if (wipe_buf && buf->b_nwindows <= 0)
787788
{
788789
tabpage_T *tp;
789790
win_T *wp;
790791

791-
// Do not wipe out the buffer if it is used in a window.
792-
if (buf->b_nwindows > 0)
793-
return FALSE;
794-
795792
FOR_ALL_TAB_WINDOWS(tp, wp)
796793
mark_forget_file(wp, buf->b_fnum);
797794

src/testdir/test_autocmd.vim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3696,7 +3696,7 @@ func Test_BufReadPre_changebuf()
36963696
close!
36973697
endfunc
36983698

3699-
" Test for BufWipeouti autocmd changing the current buffer when reading a file
3699+
" Test for BufWipeout autocmd changing the current buffer when reading a file
37003700
" in an empty buffer with 'f' flag in 'cpo'
37013701
func Test_BufDelete_changebuf()
37023702
new
@@ -4016,6 +4016,29 @@ func Test_bufwipeout_changes_window()
40164016
%bwipe!
40174017
endfunc
40184018

4019+
func Test_autocmd_prevent_buf_wipe()
4020+
" Xa must be the first buffer so that win_close_othertab() puts it in
4021+
" another window, which causes wiping the buffer to fail.
4022+
%bwipe!
4023+
4024+
file Xa
4025+
call setline(1, 'foo')
4026+
setlocal bufhidden=wipe
4027+
tabnew Xb
4028+
setlocal bufhidden=wipe
4029+
autocmd BufUnload Xa ++once ++nested tabonly
4030+
autocmd BufWinLeave Xb ++once tabnext
4031+
tabfirst
4032+
4033+
edit! Xc
4034+
call assert_equal('Xc', bufname('%'))
4035+
tabnext
4036+
call assert_equal('Xa', bufname('%'))
4037+
call assert_equal("\n\"Xa\" --No lines in buffer--", execute('file'))
4038+
4039+
%bwipe!
4040+
endfunc
4041+
40194042
func Test_v_event_readonly()
40204043
autocmd CompleteChanged * let v:event.width = 0
40214044
call assert_fails("normal! i\<C-X>\<C-V>", 'E46:')

src/version.c

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

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2055,
737739
/**/
738740
2054,
739741
/**/

0 commit comments

Comments
 (0)