Skip to content

Commit 01a060d

Browse files
committed
patch 8.1.0552: saved last search pattern may not be restored
Problem: Saved last search pattern may not be restored. Solution: Call restore_last_search_pattern(). Add a check for balancing saving and restoring the last search pattern.
1 parent 8ff5af9 commit 01a060d

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/ex_getln.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ may_do_incsearch_highlighting(
462462
int use_last_pat;
463463

464464
// Parsing range may already set the last search pattern.
465+
// NOTE: must call restore_last_search_pattern() before returning!
465466
save_last_search_pattern();
466467

467468
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
@@ -633,6 +634,7 @@ may_adjust_incsearch_highlighting(
633634
int save;
634635

635636
// Parsing range may already set the last search pattern.
637+
// NOTE: must call restore_last_search_pattern() before returning!
636638
save_last_search_pattern();
637639

638640
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
@@ -735,13 +737,15 @@ may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
735737
int skiplen, patlen;
736738

737739
// Parsing range may already set the last search pattern.
740+
// NOTE: must call restore_last_search_pattern() before returning!
738741
save_last_search_pattern();
739742

740743
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
741744
{
742745
restore_last_search_pattern();
743746
return FAIL;
744747
}
748+
restore_last_search_pattern();
745749

746750
// Add a character from under the cursor for 'incsearch'.
747751
if (is_state->did_incsearch)

src/search.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static struct spat saved_spats[2];
9696
/* copy of spats[RE_SEARCH], for keeping the search patterns while incremental
9797
* searching */
9898
static struct spat saved_last_search_spat;
99+
static int did_save_last_search_spat = 0;
99100
static int saved_last_idx = 0;
100101
static int saved_no_hlsearch = 0;
101102
# endif
@@ -364,6 +365,11 @@ free_search_patterns(void)
364365
void
365366
save_last_search_pattern(void)
366367
{
368+
if (did_save_last_search_spat != 0)
369+
IEMSG("did_save_last_search_spat is not zero");
370+
else
371+
++did_save_last_search_spat;
372+
367373
saved_last_search_spat = spats[RE_SEARCH];
368374
if (spats[RE_SEARCH].pat != NULL)
369375
saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat);
@@ -374,8 +380,16 @@ save_last_search_pattern(void)
374380
void
375381
restore_last_search_pattern(void)
376382
{
383+
if (did_save_last_search_spat != 1)
384+
{
385+
IEMSG("did_save_last_search_spat is not one");
386+
return;
387+
}
388+
--did_save_last_search_spat;
389+
377390
vim_free(spats[RE_SEARCH].pat);
378391
spats[RE_SEARCH] = saved_last_search_spat;
392+
saved_last_search_spat.pat = NULL;
379393
# if defined(FEAT_EVAL)
380394
set_vv_searchforward();
381395
# endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
552,
795797
/**/
796798
551,
797799
/**/

0 commit comments

Comments
 (0)