]> granicus.if.org Git - vim/commitdiff
patch 8.2.2420: too many problems with using all autocommand events v8.2.2420
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Jan 2021 12:47:59 +0000 (13:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Jan 2021 12:47:59 +0000 (13:47 +0100)
Problem:    Too many problems with using all autocommand events.
Solution:   Disallow defining an autocommand for all events.

src/autocmd.c
src/errors.h
src/testdir/test_autocmd.vim
src/testdir/test_quickfix.vim
src/testdir/test_window_cmd.vim
src/version.c

index f7ca41de4426485270a4657187b172553f97c830..2f6001c267edac5540604d92e76c3d0dfd3c0021 100644 (file)
@@ -956,11 +956,14 @@ do_autocmd(char_u *arg_in, int forceit)
     last_group = AUGROUP_ERROR;                // for listing the group name
     if (*arg == '*' || *arg == NUL || *arg == '|')
     {
-       for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
-                                           event = (event_T)((int)event + 1))
-           if (do_autocmd_event(event, pat,
-                                once, nested, cmd, forceit, group) == FAIL)
-               break;
+       if (!forceit && *cmd != NUL)
+           emsg(_(e_cannot_define_autocommands_for_all_events));
+       else
+           for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
+                                            event = (event_T)((int)event + 1))
+               if (do_autocmd_event(event, pat,
+                                   once, nested, cmd, forceit, group) == FAIL)
+                   break;
     }
     else
     {
index 4bd4efea697412883fc34a32dd140d45373de4c5..b2f6a55a80d6bc5c81b0d4d68fa28ead66fb2590 100644 (file)
@@ -345,3 +345,5 @@ EXTERN char e_invalid_operation_for_bool[]
        INIT(= N_("E1153: Invalid operation for bool"));
 EXTERN char e_divide_by_zero[]
        INIT(= N_("E1154: Divide by zero"));
+EXTERN char e_cannot_define_autocommands_for_all_events[]
+       INIT(= N_("E1155: Cannot define autocommands for ALL events"));
index ecef5b743b337a374093725dc6807e03baec668d..9c996ec2f765466fe6137f7378dc9b530ac67c55 100644 (file)
@@ -1827,20 +1827,9 @@ func Test_TextYankPost()
   bwipe!
 endfunc
 
-func Test_nocatch_wipe_all_buffers()
-  " Real nasty autocommand: wipe all buffers on any event.
-  au * * bwipe *
-  call assert_fails('next x', ['E94:', 'E937:'])
-  bwipe
-  au!
-endfunc
-
-func Test_nocatch_wipe_dummy_buffer()
-  CheckFeature quickfix
-  " Nasty autocommand: wipe buffer on any event.
-  au * x bwipe
-  call assert_fails('lvĀ½ /x', 'E937:')
-  au!
+func Test_autocommand_all_events()
+  call assert_fails('au * * bwipe', 'E1155:')
+  call assert_fails('au * x bwipe', 'E1155:')
 endfunc
 
 function s:Before_test_dirchanged()
index 8667631d3b6339e3005bf66f5ac5adf173b072ff..1799f2990bac3e16c0a3875b18b664db48bf5a9a 100644 (file)
@@ -3833,7 +3833,7 @@ func Test_lbuffer_crash()
   sv Xtest
   augroup QF_Test
     au!
-    au * * bw
+    au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * bw
   augroup END
   lbuffer
   augroup QF_Test
@@ -3845,7 +3845,7 @@ endfunc
 func Test_lexpr_crash()
   augroup QF_Test
     au!
-    au * * call setloclist(0, [], 'f')
+    au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call setloclist(0, [], 'f')
   augroup END
   lexpr ""
   augroup QF_Test
@@ -3880,7 +3880,7 @@ func Test_lvimgrep_crash()
   sv Xtest
   augroup QF_Test
     au!
-    au * * call setloclist(0, [], 'f')
+    au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call setloclist(0, [], 'f')
   augroup END
   lvimgrep quickfix test_quickfix.vim
   augroup QF_Test
@@ -4215,7 +4215,7 @@ func Test_lbuffer_with_bwipe()
   new
   new
   augroup nasty
-    au * * bwipe
+    au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * bwipe
   augroup END
   lbuffer
   augroup nasty
@@ -4228,9 +4228,9 @@ endfunc
 func Xexpr_acmd_freelist(cchar)
   call s:setup_commands(a:cchar)
 
-  " This was using freed memory.
+  " This was using freed memory (but with what events?)
   augroup nasty
-    au * * call g:Xsetlist([], 'f')
+    au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call g:Xsetlist([], 'f')
   augroup END
   Xexpr "x"
   augroup nasty
index f26b4474611bf87a1c01480ca1a545d5a2546223..07347a367f577e4c905fdf12f656531e98b4dde6 100644 (file)
@@ -567,8 +567,8 @@ endfunc
 
 func Test_access_freed_mem()
   call assert_equal(&columns, winwidth(0))
-  " This was accessing freed memory
-  au * 0 vs xxx
+  " This was accessing freed memory (but with what events?)
+  au BufEnter,BufLeave,WinEnter,WinLeave 0 vs xxx
   arg 0
   argadd
   call assert_fails("all", "E242:")
index 160b538c655da9afb093d27563cda0d5dbd775e2..3d0613caf59f47c5eb90e1a8ff453aa7ecf2ec6e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2420,
 /**/
     2419,
 /**/