Commit: patch 9.1.2055: Division by zero in :file after failing to wipe buffer

1 view
Skip to first unread message

Christian Brabandt

unread,
Jan 6, 2026, 6:16:08 AM (6 days ago) Jan 6
to vim...@googlegroups.com
patch 9.1.2055: Division by zero in :file after failing to wipe buffer

Commit: https://github.com/vim/vim/commit/1aa5ca4ecbef76a4df3a228e115eae7cc939cc86
Author: zeertzjq <zeer...@outlook.com>
Date: Tue Jan 6 11:11:16 2026 +0000

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 <zeer...@outlook.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/buffer.c b/src/buffer.c
index 7dca75307..1d624ae91 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -707,7 +707,7 @@ aucmd_abort:
// If the buffer was in curwin and the window has changed, go back to that
// window, if it still exists. This avoids that ":edit x" triggering a
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
- if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
+ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
{
block_autocmds();
goto_tabpage_win(the_curtab, the_curwin);
@@ -782,16 +782,13 @@ aucmd_abort:

/*
* Remove the buffer from the list.
+ * Do not wipe out the buffer if it is used in a window.
*/
- if (wipe_buf)
+ if (wipe_buf && buf->b_nwindows <= 0)
{
tabpage_T *tp;
win_T *wp;

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

diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 96b076b5e..12203cbe0 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -3696,7 +3696,7 @@ func Test_BufReadPre_changebuf()
close!
endfunc

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

+func Test_autocmd_prevent_buf_wipe()
+ " Xa must be the first buffer so that win_close_othertab() puts it in
+ " another window, which causes wiping the buffer to fail.
+ %bwipe!
+
+ file Xa
+ call setline(1, 'foo')
+ setlocal bufhidden=wipe
+ tabnew Xb
+ setlocal bufhidden=wipe
+ autocmd BufUnload Xa ++once ++nested tabonly
+ autocmd BufWinLeave Xb ++once tabnext
+ tabfirst
+
+ edit! Xc
+ call assert_equal('Xc', bufname('%'))
+ tabnext
+ call assert_equal('Xa', bufname('%'))
+ call assert_equal("
\"Xa\" --No lines in buffer--", execute('file'))
+
+ %bwipe!
+endfunc
+
func Test_v_event_readonly()
autocmd CompleteChanged * let v:event.width = 0
call assert_fails("normal! i\<C-X>\<C-V>", 'E46:')
diff --git a/src/version.c b/src/version.c
index 2f0b90769..24e5ac79a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2055,
/**/
2054,
/**/
Reply all
Reply to author
Forward
0 new messages