]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1447: completion: crash when backspacing with fuzzy completion v9.1.1447
authorzeertzjq <zeertzjq@outlook.com>
Tue, 10 Jun 2025 18:06:53 +0000 (20:06 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 10 Jun 2025 18:06:53 +0000 (20:06 +0200)
Problem:  completion: crash when backspacing with fuzzy completion
Solution: Don't dereference compl_first_match when it's NULL
          (zeertzjq).

related: neovim/neovim#34419
closes: #17511

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

index 889ea3611902ffeca20519a7a0e65df222183fdc..9ee73e15e5cc0d68d84f4cdcd6eb6b72c7a0c3e7 100644 (file)
@@ -1415,17 +1415,19 @@ cp_compare_nearest(const void* a, const void* b)
     static void
 set_fuzzy_score(void)
 {
-    if (compl_leader.string != NULL && compl_leader.length > 0)
-    {
-       compl_T *compl = compl_first_match;
+    compl_T *compl;
 
-       do
-       {
-           compl->cp_score = fuzzy_match_str(compl->cp_str.string,
-                   compl_leader.string);
-           compl = compl->cp_next;
-       } while (compl != NULL && !is_first_match(compl));
-    }
+    if (!compl_first_match
+           || compl_leader.string == NULL || compl_leader.length == 0)
+       return;
+
+    compl = compl_first_match;
+    do
+    {
+       compl->cp_score = fuzzy_match_str(compl->cp_str.string,
+               compl_leader.string);
+       compl = compl->cp_next;
+    } while (compl != NULL && !is_first_match(compl));
 }
 
 /*
@@ -1434,11 +1436,12 @@ set_fuzzy_score(void)
     static void
 sort_compl_match_list(int (*compare)(const void *, const void *))
 {
-    compl_T     *compl = compl_first_match->cp_prev;
+    compl_T     *compl;
 
     if (!compl_first_match || is_first_match(compl_first_match->cp_next))
        return;
 
+    compl = compl_first_match->cp_prev;
     ins_compl_make_linear();
     if (compl_shows_dir_forward())
     {
index 33c87cb2cb14039db12a1c3d7df738cde830b72e..155c5b79643a12a1271a0a71149d8f4d45b76262 100644 (file)
@@ -4754,4 +4754,28 @@ func Test_complete_unloaded_buf_refresh_always()
   delfunc TestComplete
 endfunc
 
+func Test_complete_fuzzy_omnifunc_backspace()
+  let g:do_complete = v:false
+  func Omni_test(findstart, base)
+    if a:findstart
+      let g:do_complete = !g:do_complete
+    endif
+    if g:do_complete
+      return a:findstart ? 0 : [#{word: a:base .. 'def'}, #{word: a:base .. 'ghi'}]
+    endif
+    return a:findstart ? -3 : {}
+  endfunc
+
+  new
+  setlocal omnifunc=Omni_test
+  setlocal completeopt=menuone,fuzzy,noinsert
+  call setline(1, 'abc')
+  call feedkeys("A\<C-X>\<C-O>\<BS>\<Esc>0", 'tx!')
+  call assert_equal('ab', getline(1))
+
+  bwipe!
+  delfunc Omni_test
+  unlet g:do_complete
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index b384859de3d43bf72d793574c313ad0f5bda30cf..05be1d862ad9030526bf34522f40e28022e6f108 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1447,
 /**/
     1446,
 /**/