From d5eff30c72fda97aa5f075718b3e1fef7c1baa4f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 12 Sep 2020 18:42:48 -0400 Subject: vim-patch:8.1.0555: crash when last search pat is set but not last substitute pat Problem: Crash when last search pat is set but not last substitute pat. Solution: Do not mix up last search pattern and last subtitute pattern. (closes vim/vim#3647) https://github.com/vim/vim/commit/2fb8f684d888ad68b283ba8f9505106b5fb725be --- src/nvim/search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 23d84038d6..08da391f97 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1179,7 +1179,7 @@ int do_search( } if (*searchstr == NUL) { - p = spats[last_idx].pat; + p = spats[0].pat; } else { p = searchstr; } -- cgit From ce325457083e8fac376028887a80e47e1f6e7d09 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 12 Sep 2020 19:04:01 -0400 Subject: vim-patch:8.1.0556: saving/restoring search patterns share saved last_idx Problem: Saving/restoring search patterns share saved last_idx. Solution: Use a separate saved last_idx for saving search patterns for functions and incremental search. https://github.com/vim/vim/commit/ed8bc78d2386d22656ba1d3e5cf739dd12964dce --- src/nvim/search.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 08da391f97..d7984d675d 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -96,12 +96,8 @@ static int lastc_bytelen = 1; // >1 for multi-byte char // copy of spats[], for keeping the search patterns while executing autocmds static struct spat saved_spats[2]; -// copy of spats[RE_SEARCH], for keeping the search patterns while incremental -// searching -static struct spat saved_last_search_spat; -static int did_save_last_search_spat = 0; -static int saved_last_idx = 0; -static bool saved_no_hlsearch = false; +static int saved_spats_last_idx = 0; +static bool saved_spats_no_hlsearch = false; static char_u *mr_pattern = NULL; // pattern used by search_regcomp() static int mr_pattern_alloced = false; // mr_pattern was allocated @@ -268,8 +264,8 @@ void save_search_patterns(void) saved_spats[1] = spats[1]; if (spats[1].pat != NULL) saved_spats[1].pat = vim_strsave(spats[1].pat); - saved_last_idx = last_idx; - saved_no_hlsearch = no_hlsearch; + saved_spats_last_idx = last_idx; + saved_spats_no_hlsearch = no_hlsearch; } } @@ -281,8 +277,8 @@ void restore_search_patterns(void) set_vv_searchforward(); free_spat(&spats[1]); spats[1] = saved_spats[1]; - last_idx = saved_last_idx; - set_no_hlsearch(saved_no_hlsearch); + last_idx = saved_spats_last_idx; + set_no_hlsearch(saved_spats_no_hlsearch); } } @@ -309,6 +305,13 @@ void free_search_patterns(void) #endif +// copy of spats[RE_SEARCH], for keeping the search patterns while incremental +// searching +static struct spat saved_last_search_spat; +static int did_save_last_search_spat = 0; +static int saved_last_idx = 0; +static bool saved_no_hlsearch = false; + /// Save and restore the search pattern for incremental highlight search /// feature. /// @@ -488,7 +491,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) saved_spats[idx].pat = NULL; else saved_spats[idx].pat = vim_strsave(spats[idx].pat); - saved_last_idx = last_idx; + saved_spats_last_idx = last_idx; } /* If 'hlsearch' set and search pat changed: need redraw. */ if (p_hls && idx == last_idx && !no_hlsearch) -- cgit From 4327fe8da54ad090e3ca08473ff198ad7cc1f448 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 12 Sep 2020 19:26:56 -0400 Subject: vim-patch:8.2.0902: using searchcount() in 'statusline' causes an error Problem: Using searchcount() in 'statusline' causes an error. Solution: Avoid saving/restoring the search patten recursively. (closes vim/vim#6194) https://github.com/vim/vim/commit/442a85369f3eb9834dbab42add45f7c4106700f4 --- src/nvim/search.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index d7984d675d..517db05a40 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -320,10 +320,9 @@ static bool saved_no_hlsearch = false; /// cancelling incremental searching even if it's called inside user functions. void save_last_search_pattern(void) { - if (did_save_last_search_spat != 0) { - IEMSG("did_save_last_search_spat is not zero"); - } else { - did_save_last_search_spat++; + if (++did_save_last_search_spat != 1) { + // nested call, nothing to do + return; } saved_last_search_spat = spats[RE_SEARCH]; @@ -336,11 +335,15 @@ void save_last_search_pattern(void) void restore_last_search_pattern(void) { - if (did_save_last_search_spat != 1) { - IEMSG("did_save_last_search_spat is not one"); + if (--did_save_last_search_spat > 0) { + // nested call, nothing to do + return; + } + if (did_save_last_search_spat != 0) { + iemsg("restore_last_search_pattern() called more often than" + " save_last_search_pattern()"); return; } - did_save_last_search_spat--; xfree(spats[RE_SEARCH].pat); spats[RE_SEARCH] = saved_last_search_spat; -- cgit