diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-04-27 23:00:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 23:00:28 +0200 |
commit | f65043154e023263bc98057b1792893ef2bfee18 (patch) | |
tree | f3c1f735e18c5fbcc400bcfe659dc737e1ce2eb5 | |
parent | c50cdd62706ed00a2bb9e1201ac8aac1b71e9a16 (diff) | |
parent | 774a32e5fe732a43b229ab25e24dffa36ac29aa4 (diff) | |
download | rneovim-f65043154e023263bc98057b1792893ef2bfee18.tar.gz rneovim-f65043154e023263bc98057b1792893ef2bfee18.tar.bz2 rneovim-f65043154e023263bc98057b1792893ef2bfee18.zip |
Merge pull request #23356 from ii14/fix/23355
fix(events): null dereference in autocmd functions
-rw-r--r-- | src/nvim/autocmd.c | 6 | ||||
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 7a65f11e80..b5109b4b21 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -300,7 +300,7 @@ void aucmd_del_for_event_and_group(event_T event, int group) AutoCmdVec *const acs = &autocmds[(int)event]; for (size_t i = 0; i < kv_size(*acs); i++) { AutoCmd *const ac = &kv_A(*acs, i); - if (ac->pat->group == group) { + if (ac->pat != NULL && ac->pat->group == group) { aucmd_del(ac); } } @@ -2027,6 +2027,7 @@ char *getnextac(int c, void *cookie, int indent, bool do_concat) assert(apc->auidx < kv_size(*acs)); AutoCmd *const ac = &kv_A(*acs, apc->auidx); + assert(ac->pat != NULL); bool oneshot = ac->once; if (p_verbose >= 9) { @@ -2288,7 +2289,8 @@ bool au_exists(const char *const arg) AutoPat *const ap = kv_A(*acs, i).pat; // Only use a pattern when it has not been removed. // For buffer-local autocommands, path_fnamecmp() works fine. - if ((group == AUGROUP_ALL || ap->group == group) + if (ap != NULL + && (group == AUGROUP_ALL || ap->group == group) && (pattern == NULL || (buflocal_buf == NULL ? path_fnamecmp(ap->pat, pattern) == 0 diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 82c7f9502f..da8c7b5ee0 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -629,4 +629,20 @@ describe('autocmd', function() ]] eq(1, eval('g:count')) -- Added autocommands should not be executed end) + + it('no crash when clearing a group inside a callback #23355', function() + exec_lua [[ + vim.cmd "autocmd! TabNew" + local group = vim.api.nvim_create_augroup('Test', {}) + local id + id = vim.api.nvim_create_autocmd('TabNew', { + group = group, + callback = function() + vim.api.nvim_del_autocmd(id) + vim.api.nvim_create_augroup('Test', { clear = true }) + end, + }) + vim.cmd "tabnew" + ]] + end) end) |