From 245522db1eb294007066878492d19295a5e91f04 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Jan 2023 12:24:24 +0800 Subject: [PATCH] vim-patch:8.2.4478: crash when using fuzzy completion Problem: Crash when using fuzzy completion. Solution: Temporary fix: put back regexp. (closes vim/vim#9852, closes vim/vim#9851) https://github.com/vim/vim/commit/00333cb3b341499df8729b9345f0bbad968cda0b Co-authored-by: Yegappan Lakshmanan --- src/nvim/cmdexpand.c | 20 +++++++++++++------- src/nvim/testdir/test_cmdline.vim | 4 ++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 2f2545412b..f6b5127268 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2636,6 +2636,8 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM regmatch_T regmatch = { .rm_ic = false }; int ret; int flags = map_wildopts_to_ewflags(options); + const bool fuzzy = cmdline_fuzzy_complete(pat) + && cmdline_fuzzy_completion_supported(xp); if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES @@ -2716,13 +2718,15 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM return nlua_expand_pat(xp, pat, numMatches, matches); } - regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0); - if (regmatch.regprog == NULL) { - return FAIL; - } + if (!fuzzy) { + regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0); + if (regmatch.regprog == NULL) { + return FAIL; + } - // set ignore-case according to p_ic, p_scs and pat - regmatch.rm_ic = ignorecase(pat); + // set ignore-case according to p_ic, p_scs and pat + regmatch.rm_ic = ignorecase(pat); + } if (xp->xp_context == EXPAND_SETTINGS || xp->xp_context == EXPAND_BOOL_SETTINGS) { @@ -2735,7 +2739,9 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM ret = ExpandOther(pat, xp, ®match, matches, numMatches); } - vim_regfree(regmatch.regprog); + if (!fuzzy) { + vim_regfree(regmatch.regprog); + } xfree(tofree); return ret; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 16d99cf4c5..4c59a8ab7c 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2869,6 +2869,10 @@ func Test_wildoptions_fuzzy() call assert_equal('"mapclear ', @:) " map name fuzzy completion - NOT supported + " test regex completion works + set wildoptions=fuzzy + call feedkeys(":cnoremap \\\"\", 'tx') + call assert_equal("\"cnoremap \", @:) " menu name fuzzy completion if has('gui_running')