patch 9.1.1445: negative matchfuzzy scores although there is a match

Commit: 
https://github.com/vim/vim/commit/328332b0b03ff6a709ed319b83429390ee8394d8
Author: Girish Palya <giris...@gmail.com>
Date:   Mon Jun 9 20:43:03 2025 +0200

    patch 9.1.1445: negative matchfuzzy scores although there is a match
    
    Problem:  negative matchfuzzy scores although there is a match
              (Maxim Kim)
    Solution: reset the score if a match has been found but the score is
              negative (Girish Palya)
    
    The fuzzy algorithm may miss some matches in long strings due to recursion
    limits. As a result, the score can end up negative even when matches exist.
    In such cases, reset the score to ensure it is non-negative.
    
    fixes: ##17449
    closes: #17469
    
    Signed-off-by: Girish Palya <giris...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/search.c b/src/search.c
index 14990e2a2..425d0d3b5 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4413,6 +4413,10 @@ fuzzy_match_compute_score(
     // Apply unmatched penalty
     unmatched = strSz - numMatches;
     score += UNMATCHED_LETTER_PENALTY * unmatched;
+    // In a long string, not all matches may be found due to the recursion 
limit.
+    // If at least one match is found, reset the score to a non-negative value.
+    if (score < 0 && numMatches > 0)
+       score = 0;
 
     // Apply ordering bonuses
     for (i = 0; i < numMatches; ++i)
diff --git a/src/testdir/test_matchfuzzy.vim b/src/testdir/test_matchfuzzy.vim
index 7e35d3547..a16bae5ee 100644
--- a/src/testdir/test_matchfuzzy.vim
+++ b/src/testdir/test_matchfuzzy.vim
@@ -125,7 +125,7 @@ func Test_matchfuzzypos()
   call assert_equal([[], [], []], matchfuzzypos([], 'abc'))
 
   " match in a long string
-  call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]], [-60]],
+  call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]], [155]],
         \ matchfuzzypos([repeat('x', 300) .. 'abc'], 'abc'))
 
   " preference for camel case match
@@ -258,7 +258,7 @@ func Test_matchfuzzypos_mbyte()
   call assert_equal([[], [], []], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 
돼지']->matchfuzzypos('파란 하늘'))
 
   " match in a long string
-  call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]], [-110]],
+  call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]], [105]],
         \ matchfuzzypos([repeat('ぶ', 300) .. 'ẼẼẼ'], 'ẼẼẼ'))
   " preference for camel case match
   call assert_equal([['xѳѵҁxxѳѴҁ'], [[6, 7, 8]], [219]], 
matchfuzzypos(['xѳѵҁxxѳѴҁ'], 'ѳѵҁ'))
diff --git a/src/version.c b/src/version.c
index ec8c923a0..2b14b1555 100644
--- a/src/version.c
+++ b/src/version.c
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1445,
 /**/
     1444,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1uOhj1-009s9w-TB%40256bit.org.

Raspunde prin e-mail lui