]> granicus.if.org Git - vim/commitdiff
patch 8.2.2473: crash when leaving command line window triggers autocommand v8.2.2473
authorBram Moolenaar <Bram@vim.org>
Sat, 6 Feb 2021 17:08:45 +0000 (18:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 6 Feb 2021 17:08:45 +0000 (18:08 +0100)
Problem:    Crash when leaving command line window triggers autocommand.
            (houyunsong)
Solution:   Make sure not to close the current window or buffer.

src/ex_getln.c
src/testdir/test_autocmd.vim
src/version.c

index d6712c126a2cf5fc387fd0b38564adfdd8de1fe3..faa56e14b6e225cfb1161c3323f4bdfa9512f7a9 100644 (file)
@@ -4403,12 +4403,12 @@ open_cmdwin(void)
 
        // win_goto() may trigger an autocommand that already closes the
        // cmdline window.
-       if (win_valid(wp))
+       if (win_valid(wp) && wp != curwin)
            win_close(wp, TRUE);
 
        // win_close() may have already wiped the buffer when 'bh' is
-       // set to 'wipe'
-       if (bufref_valid(&bufref))
+       // set to 'wipe', autocommands may have closed other windows
+       if (bufref_valid(&bufref) && bufref.br_buf != curbuf)
            close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE, FALSE);
 
        // Restore window sizes.
index 8ccc753df2e2960be08cb03c62fa5d8a9845ba23..15d237ee1d3ebddf0b28d82ad722095b8c67001b 100644 (file)
@@ -2774,4 +2774,13 @@ func Test_autocmd_normal_mess()
   augroup END
 endfunc
 
+func Test_autocmd_closing_cmdwin()
+  au BufWinLeave * nested q
+  call assert_fails("norm 7q?\n", 'E855:')
+
+  au! BufWinLeave
+  new
+  only
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 1b0faaeee7ea075fe6fd7ab584b712cd5cc7b624..254aafdb8ebd1c788312355b4c4f267d386909cb 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2473,
 /**/
     2472,
 /**/