diff src/search.c @ 20697:1260b27535b5 v8.2.0902

patch 8.2.0902: using searchcount() in 'statusline' causes an error Commit: https://github.com/vim/vim/commit/442a85369f3eb9834dbab42add45f7c4106700f4 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 4 20:56:09 2020 +0200 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 #6194)
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Jun 2020 21:00:03 +0200
parents 4c66962d322b
children 9064044fd4f6
line wrap: on
line diff
--- a/src/search.c
+++ b/src/search.c
@@ -356,10 +356,9 @@ static int	    saved_no_hlsearch = 0;
     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];
     if (spats[RE_SEARCH].pat != NULL)
@@ -371,12 +370,14 @@ save_last_search_pattern(void)
     void
 restore_last_search_pattern(void)
 {
-    if (did_save_last_search_spat != 1)
+    if (--did_save_last_search_spat > 0)
+	// nested call, nothing to do
+	return;
+    if (did_save_last_search_spat != 0)
     {
-	iemsg("did_save_last_search_spat is not one");
+	iemsg("restore_last_search_pattern() called more often than save_last_search_pattern()");
 	return;
     }
-    --did_save_last_search_spat;
 
     vim_free(spats[RE_SEARCH].pat);
     spats[RE_SEARCH] = saved_last_search_spat;