Commit: patch 9.1.1395: search_stat not reset when pattern differs in case

1 view
Skip to first unread message

Christian Brabandt

unread,
May 16, 2025, 1:45:20 PM5/16/25
to vim...@googlegroups.com
patch 9.1.1395: search_stat not reset when pattern differs in case

Commit: https://github.com/vim/vim/commit/670d0c1468b7ece958acf3b03de9e202e612804a
Author: Christian Brabandt <c...@256bit.org>
Date: Fri May 16 19:38:50 2025 +0200

patch 9.1.1395: search_stat not reset when pattern differs in case

Problem: search_stat not reset when pattern differs in case
(tahzibijafar)
Solution: use STRNCMP instead of MB_STRNICMP macro

There was a long standing todo comment, that using MB_STRNICMP is wrong.
So let's change it to STRNCMP() instead. Even if it not handle
multi-byte characters correctly, then Vim will rather recompute the
search stat, instead of re-using the old (and possibly wrong) value.

fixes: #17312
closes: #17314

Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/search.c b/src/search.c
index ea7e65492..14990e2a2 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3291,12 +3291,9 @@ update_search_stat(
|| (dirc == '/' && LT_POS(p, lastpos)));

// If anything relevant changed the count has to be recomputed.
- // MB_STRNICMP ignores case, but we should not ignore case.
- // Unfortunately, there is no MB_STRNICMP function.
- // XXX: above comment should be "no MB_STRCMP function" ?
if (!(chgtick == CHANGEDTICK(curbuf)
&& (lastpat != NULL
- && MB_STRNICMP(lastpat, spats[last_idx].pat, lastpatlen) == 0
+ && STRNCMP(lastpat, spats[last_idx].pat, lastpatlen) == 0
&& lastpatlen == spats[last_idx].patlen
)
&& EQUAL_POS(lastpos, *cursor_pos)
diff --git a/src/testdir/test_search_stat.vim b/src/testdir/test_search_stat.vim
index b57b7ba7b..c8e055d7d 100644
--- a/src/testdir/test_search_stat.vim
+++ b/src/testdir/test_search_stat.vim
@@ -459,4 +459,23 @@ func Test_search_stat_backwards()
call StopVimInTerminal(buf)
endfunc

+func Test_search_stat_smartcase_ignorecase()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set shm-=S ignorecase smartcase
+ call setline(1, [' MainmainmainmmmainmAin', ''])
+ END
+ call writefile(lines, 'Xsearchstat_ignorecase', '5')
+
+ let buf = RunVimInTerminal('-S Xsearchstat_ignorecase', #{rows: 10})
+ call term_sendkeys(buf, "/main\<cr>nnnn")
+ call WaitForAssert({-> assert_match('\[5\/5\]', term_getline(buf, 10))}, 1000)
+
+ call term_sendkeys(buf, "/mAin\<cr>")
+ call WaitForAssert({-> assert_match('\[1\/1\]', term_getline(buf, 10))}, 1000)
+
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 4e8567035..e367036ea 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 */
+/**/
+ 1395,
/**/
1394,
/**/
Reply all
Reply to author
Forward
0 new messages