From e4007551c4af5cd3bb6be2923cb375581d11a010 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 14 Apr 2025 13:02:58 +0800 Subject: [PATCH] fix(completion): avoid freeing uninitialized value (#33459) (cherry picked from commit 51caf0a3af599bc4eacdc4b87092bb20286dbfe8) --- src/nvim/cmdexpand.c | 2 +- test/functional/api/command_spec.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 28cc70ff5a..5c3b17b903 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3242,7 +3242,7 @@ static int ExpandUserList(expand_T *xp, char ***matches, int *numMatches) static int ExpandUserLua(expand_T *xp, int *num_file, char ***file) { - typval_T rettv; + typval_T rettv = TV_INITIAL_VALUE; nlua_call_user_expand_func(xp, &rettv); if (rettv.v_type != VAR_LIST) { tv_clear(&rettv); diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index fabd9be6d6..d332576fb4 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -681,6 +681,19 @@ describe('nvim_create_user_command', function() eq('Test bbb', fn.getcmdline()) end) + it('no crash when Lua complete function errors #33447', function() + exec_lua([[ + vim.api.nvim_create_user_command('Test','', { + nargs = 1, + complete = function() error() end + }) + ]]) + feed(':Test ') + eq('E5108: Error executing Lua function: [NULL]', api.nvim_get_vvar('errmsg')) + eq('Test ', fn.getcmdline()) + assert_alive() + end) + it('does not allow invalid command names', function() eq( "Invalid command name (must start with uppercase): 'test'",