patch 8.0.1115: crash when using foldtextresult() recursively
Problem: Crash when using foldtextresult() recursively.
Solution: Avoid recursive calls. (Yasuhiro Matsumoto, closes #2098)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 63aa34c..d438a89 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3642,11 +3642,16 @@
char_u buf[FOLD_TEXT_LEN];
foldinfo_T foldinfo;
int fold_count;
+ static int entered = FALSE;
#endif
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
#ifdef FEAT_FOLDING
+ if (entered)
+ return; /* reject recursive use */
+ entered = TRUE;
+
lnum = get_tv_lnum(argvars);
/* treat illegal types and illegal string values for {lnum} the same */
if (lnum < 0)
@@ -3660,6 +3665,8 @@
text = vim_strsave(text);
rettv->vval.v_string = text;
}
+
+ entered = FALSE;
#endif
}