vim-patch:9.1.1445: negative matchfuzzy scores although there is a match (#34409)

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: #vim/vim#17449
closes: vim/vim#17469

328332b0b0

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-06-10 08:47:14 +08:00
committed by GitHub
parent 7a58cf4b96
commit bcba067dc2
2 changed files with 7 additions and 2 deletions

View File

@@ -3021,6 +3021,11 @@ static int fuzzy_match_compute_score(const char *const fuzpat, const char *const
// Apply unmatched penalty
const int 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 (int i = 0; i < numMatches; i++) {