Skip to content

Commit

Permalink
patch 9.0.1555: setcharsearch() does not clear last searched char pro…
Browse files Browse the repository at this point in the history
…perly

Problem:    setcharsearch() does not clear last searched char properly.
Solution:   Do not accept lastc_bytelen smaller than one. (closes #12398)
  • Loading branch information
zeertzjq authored and brammool committed May 14, 2023
1 parent e42c27d commit e5d91ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/search.c
Expand Up @@ -496,7 +496,7 @@ last_csearch_until(void)
}

void
set_last_csearch(int c, char_u *s UNUSED, int len UNUSED)
set_last_csearch(int c, char_u *s, int len)
{
*lastc = c;
lastc_bytelen = len;
Expand Down Expand Up @@ -1789,7 +1789,7 @@ searchc(cmdarg_T *cap, int t_cmd)
}
else // repeat previous search
{
if (*lastc == NUL && lastc_bytelen == 1)
if (*lastc == NUL && lastc_bytelen <= 1)
return FAIL;
if (dir) // repeat in opposite direction
dir = -lastcdir;
Expand Down Expand Up @@ -1833,7 +1833,7 @@ searchc(cmdarg_T *cap, int t_cmd)
return FAIL;
col -= (*mb_head_off)(p, p + col - 1) + 1;
}
if (lastc_bytelen == 1)
if (lastc_bytelen <= 1)
{
if (p[col] == c && stop)
break;
Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_charsearch.vim
Expand Up @@ -38,6 +38,8 @@ func Test_charsearch()
" clear the character search
call setcharsearch({'char' : ''})
call assert_equal('', getcharsearch().char)
call assert_beeps('normal ;')
call assert_beeps('normal ,')

call assert_fails("call setcharsearch([])", 'E1206:')
enew!
Expand Down
7 changes: 7 additions & 0 deletions src/testdir/test_charsearch_utf8.vim
Expand Up @@ -13,6 +13,13 @@ func Test_search_cmds()
call assert_equal([0, 1, 43, 0], getpos('.'))
normal! ,
call assert_equal([0, 1, 28, 0], getpos('.'))
call assert_equal('', getcharsearch().char)
call setcharsearch({'char' : ''})
call assert_equal('', getcharsearch().char)
call assert_beeps('normal ;')
call assert_equal([0, 1, 28, 0], getpos('.'))
call assert_beeps('normal ,')
call assert_equal([0, 1, 28, 0], getpos('.'))
bw!
endfunc

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1555,
/**/
1554,
/**/
Expand Down

0 comments on commit e5d91ba

Please sign in to comment.