]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0471: Crash when using autocmd_get() after removing event inside autocmd v9.1.0471
authorzeertzjq <zeertzjq@outlook.com>
Sun, 9 Jun 2024 14:44:33 +0000 (16:44 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 9 Jun 2024 14:44:33 +0000 (16:44 +0200)
Problem:  Crash when using autocmd_get() after removing event inside
          autocmd (Sergey Vlasov)
Solution: Check that the pattern is NULL (zeertzjq).

fixes: #14937
closes: #14939

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/autocmd.c
src/testdir/test_autocmd.vim
src/version.c

index bce57cb759e06299a5b9e5f1ab0c761a65667902..8380f8a04e4e7b7cf69ce3da138fb0e86c0d39b8 100644 (file)
@@ -3391,6 +3391,9 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
        {
            char_u      *group_name;
 
+           if (ap->pat == NULL)                // pattern has been removed
+               continue;
+
            if (group != AUGROUP_ALL && group != ap->group)
                continue;
 
index 24e1daf77a3bb6a96aaf64aff1f23ba9cfe0ecc2..c9f257a87cfa208e025b2fc52a7128bc295c5ef3 100644 (file)
@@ -4024,6 +4024,32 @@ func Test_autocmd_get()
         \ event: 'BufAdd', pattern: '*.abc'}))
   call assert_equal([], autocmd_get(#{group: 'TestAutoCmdFns',
         \ event: 'BufWipeout'}))
+
+  " Test for getting autocmds after removing one inside an autocmd
+  func CheckAutocmdGet()
+    augroup TestAutoCmdFns
+      autocmd! BufAdd *.vim
+    augroup END
+
+    let expected = [
+          \ #{cmd: 'echo "bufadd-py"', group: 'TestAutoCmdFns',
+          \  pattern: '*.py', nested: v:false, once: v:false,
+          \  event: 'BufAdd'},
+          \ #{cmd: 'echo "bufhidden"', group: 'TestAutoCmdFns',
+          \  pattern: '*.vim', nested: v:false,
+          \  once: v:false, event: 'BufHidden'}]
+
+    call assert_equal(expected, autocmd_get(#{group: 'TestAutoCmdFns'}))
+    call assert_equal([expected[0]],
+          \ autocmd_get(#{group: 'TestAutoCmdFns', pattern: '*.py'}))
+    call assert_equal([expected[1]],
+          \ autocmd_get(#{group: 'TestAutoCmdFns', pattern: '*.vim'}))
+  endfunc
+
+  autocmd User Xauget call CheckAutocmdGet()
+  doautocmd User Xauget
+  autocmd! User Xauget
+
   call assert_fails("call autocmd_get(#{group: 'abc', event: 'BufAdd'})",
         \ 'E367:')
   let cmd = "echo autocmd_get(#{group: 'TestAutoCmdFns', event: 'abc'})"
index 50a34c8c794ff4323bdb3e80327e5ac2e1dc03f3..40186dd5000716f4a9feccaec148346de3c3209e 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    471,
 /**/
     470,
 /**/