patch 9.1.1393: missing test for switching buffers and reusing curbuf
Commit:
https://github.com/vim/vim/commit/31be82e66d412000f1d964a36bb8a03d40eaaeac
Author: Sean Dewar <[email protected]>
Date: Thu May 15 19:59:37 2025 +0200
patch 9.1.1393: missing test for switching buffers and reusing curbuf
Problem: The check in buf_freeall that restores curwin subtly prevents
leaving an unloaded buffer in a window when reusing curbuf, if
autocommands switch to a different buffer.
Solution: Add a test case that covers this. Also ensure splitting isn't
possible, as that could do the same (Sean Dewar)
closes: #17325
Signed-off-by: Sean Dewar <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/buffer.c b/src/buffer.c
index 49ec77c7b..48e8cb63b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -909,7 +909,7 @@ buf_freeall(buf_T *buf, int flags)
// 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);
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 26f714565..1988807f7 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -5415,4 +5415,31 @@ func Test_reuse_curbuf_leak()
%bw!
endfunc
+func Test_reuse_curbuf_switch()
+ edit asdf
+ let s:asdf_win = win_getid()
+ new
+ let other_buf = bufnr()
+ let other_win = win_getid()
+ augroup testing
+ autocmd!
+ autocmd BufUnload * ++once let s:triggered = 1
+ \| call assert_fails('split', 'E1159:')
+ \| call win_gotoid(s:asdf_win)
+ augroup END
+
+ " Check BufUnload changing curbuf does not cause buflist_new to create a new
+ " buffer while leaving "other_buf" unloaded in a window.
+ enew
+ call assert_equal(1, s:triggered)
+ call assert_equal(other_buf, bufnr())
+ call assert_equal(other_win, win_getid())
+ call assert_equal(1, win_findbuf(other_buf)->len())
+ call assert_equal(1, bufloaded(other_buf))
+
+ unlet! s:asdf_win s:triggered
+ call CleanUpTestAuGroup()
+ %bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index e4651653b..ffcfccb2d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -709,6 +709,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1393,
/**/
1392,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1uFd6p-00CYWv-4Y%40256bit.org.