]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1185: endless loop with completefuzzycollect and no match found v9.1.1185
authorglepnir <glephunter@gmail.com>
Sat, 8 Mar 2025 15:52:55 +0000 (16:52 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 8 Mar 2025 15:52:55 +0000 (16:52 +0100)
Problem:  endless loop with completefuzzycollect and no match found
Solution: move pointer to line end and break loop

closes: #16820

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/insexpand.c
src/proto/insexpand.pro
src/search.c
src/testdir/test_ins_complete.vim
src/version.c

index f7700413102e486fc9bd0ddbaf3f600d891b29dc..d8bb0814d3f40a99877e5a59f00c957e0ea1e4b4 100644 (file)
@@ -217,7 +217,6 @@ static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, t
 static void ins_compl_longest_match(compl_T *match);
 static void ins_compl_del_pum(void);
 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
-static char_u *find_line_end(char_u *ptr);
 static void ins_compl_free(void);
 static int  ins_compl_need_restart(void);
 static void ins_compl_new_leader(void);
@@ -1870,8 +1869,6 @@ ins_compl_files(
                                && score == compl_first_match->cp_next->cp_score)
                            compl_num_bests++;
                    }
-                   else if (find_word_end(ptr) == line_end)
-                       break;
                }
            }
            line_breakcheck();
@@ -1927,7 +1924,7 @@ find_word_end(char_u *ptr)
  * Find the end of the line, omitting CR and NL at the end.
  * Returns a pointer to just after the line.
  */
-    static char_u *
+    char_u *
 find_line_end(char_u *ptr)
 {
     char_u     *s;
index 8d961642623a8ce9b2f6a8f18b366f016e3a019e..2d1d12cd1ae3d5747992542e8ea2384921365c73 100644 (file)
@@ -65,4 +65,6 @@ int ins_compl_col_range_attr(linenr_T lnum, int col);
 void free_insexpand_stuff(void);
 int ins_compl_preinsert_effect(void);
 int ins_compl_lnum_in_range(linenr_T lnum);
+char_u *find_line_end(char_u *ptr);
+
 /* vim: set ft=c : */
index 67082a731fe4ddd2b017c3edb2c6d204bc63b5cb..654b8968b56c5848b2696bd5e40c0c7c5f4908bc 100644 (file)
@@ -5229,8 +5229,7 @@ fuzzy_match_str_with_pos(char_u *str UNUSED, char_u *pat UNUSED)
  * - `*len` is set to the length of the matched word.
  * - `*score` contains the match score.
  *
- * If no match is found, `*ptr` is updated to point beyond the last word
- * or to the end of the line.
+ * If no match is found, `*ptr` is updated to to the end of the line.
  */
     int
 fuzzy_match_str_in_line(
@@ -5246,11 +5245,13 @@ fuzzy_match_str_in_line(
     char_u     *start = NULL;
     int                found = FALSE;
     char       save_end;
+    char_u     *line_end = NULL;
 
     if (str == NULL || pat == NULL)
         return found;
+    line_end = find_line_end(str);
 
-    while (*str != NUL)
+    while (str < line_end)
     {
        // Skip non-word characters
        start = find_word_start(str);
@@ -5283,6 +5284,9 @@ fuzzy_match_str_in_line(
            MB_PTR_ADV(str);
     }
 
+    if (!found)
+       *ptr = line_end;
+
     return found;
 }
 
index 345e365ddfe38c335d56a146b7bae235d95df9c7..e63b13334a0d2739415c5633e8a3d6b37b2e0bd4 100644 (file)
@@ -3005,6 +3005,11 @@ func Test_cfc_with_longest()
   call writefile(['  auto int   enum register', 'why'], 'test_case4.txt', 'D')
   exe "normal ggdGSe\<C-N>\<C-N>\<ESC>"
   call assert_equal("enum", getline('.'))
+
+  set complete=ktest_case5.txt
+  call writefile(['hello friends', 'go', 'hero'], 'test_case5.txt', 'D')
+  exe "normal ggdGSh\<C-N>\<C-N>\<ESC>"
+  call assert_equal("hero", getline('.'))
   set complete&
 
   " file
index 8223d0c2bfa8428ec8d2f2cf693c53b1b621b4c1..1bfcbcbd0b4153da1d7841b26760917e114b335d 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1185,
 /**/
     1184,
 /**/