]> granicus.if.org Git - vim/commitdiff
patch 8.2.1059: crash when using :tabonly in an autocommand v8.2.1059
authorBram Moolenaar <Bram@vim.org>
Fri, 26 Jun 2020 17:44:06 +0000 (19:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Jun 2020 17:44:06 +0000 (19:44 +0200)
Problem:    Crash when using :tabonly in an autocommand. (Yegappan Lakshmanan)
Solution:   Do not allow the autocommand window to be closed.

src/ex_docmd.c
src/globals.h
src/testdir/test_autocmd.vim
src/version.c
src/window.c

index 6c887fae1c2ea452afb05dfb04054a9c246aa8cb..2469df341c687ad7048a73c14b0646253fdb3010 100644 (file)
@@ -5178,6 +5178,13 @@ ex_win_close(
     int                need_hide;
     buf_T      *buf = win->w_buffer;
 
+    // Never close the autocommand window.
+    if (win == aucmd_win)
+    {
+       emsg(_(e_autocmd_close));
+       return;
+    }
+
     need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
     if (need_hide && !buf_hide(buf) && !forceit)
     {
index c7f9794ab934238480a8f8fb473d49c6a10be53f..03a6937561b291cf33adbf7cab0274644a27eabc 100644 (file)
@@ -1765,6 +1765,7 @@ EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String"));
 #endif
 EXTERN char e_dirnotf[]        INIT(= N_("E919: Directory not found in '%s': \"%s\""));
 EXTERN char e_au_recursive[]   INIT(= N_("E952: Autocommand caused recursive behavior"));
+EXTERN char e_autocmd_close[]  INIT(= N_("E813: Cannot close autocmd or popup window"));
 #ifdef FEAT_MENU
 EXTERN char e_menuothermode[]  INIT(= N_("E328: Menu only exists in another mode"));
 #endif
index d7328c3e0a5a553f02fbe26f73893b1c207b8486..446d22bd710b886da2eadcb372389df1c9891baa 100644 (file)
@@ -2617,7 +2617,27 @@ func Test_close_autocmd_window()
     au!
   augroup END
   augroup! aucmd_win_test2
-  %bw!
+  %bwipe!
+endfunc
+
+" Test for trying to close the tab that has the temporary window for exeucing
+" an autocmd.
+func Test_close_autocmd_tab()
+  edit one.txt
+  tabnew two.txt
+   augroup aucmd_win_test
+    au!
+    au BufEnter * if expand('<afile>') == 'one.txt' | tabfirst | tabonly | endif
+  augroup END
+
+  call assert_fails('doautoall BufEnter', 'E813:')
+
+  tabonly
+  augroup aucmd_win_test
+    au!
+  augroup END
+  augroup! aucmd_win_test
+  %bwipe!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index de8807a528b879cfa512e953e05c9179c72544a1..aff4583e948cc1a74a7b569f8572e08bbcde8c41 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1059,
 /**/
     1058,
 /**/
index 095eabed2bf8f9e2fd16b2ea5cd616b7846da77b..e2adc0cb9faa78f7935ecadfe9f1ff1489981309 100644 (file)
@@ -2461,7 +2461,7 @@ win_close(win_T *win, int free_buf)
        return FAIL; // window is already being closed
     if (win_unlisted(win))
     {
-       emsg(_("E813: Cannot close autocmd or popup window"));
+       emsg(_(e_autocmd_close));
        return FAIL;
     }
     if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window())