Skip to content

Commit 495b7dd

Browse files
committed
patch 8.0.1115: crash when using foldtextresult() recursively
Problem: Crash when using foldtextresult() recursively. Solution: Avoid recursive calls. (Yasuhiro Matsumoto, closes #2098)
1 parent 4cf56bb commit 495b7dd

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/evalfunc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,11 +3642,16 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
36423642
char_u buf[FOLD_TEXT_LEN];
36433643
foldinfo_T foldinfo;
36443644
int fold_count;
3645+
static int entered = FALSE;
36453646
#endif
36463647

36473648
rettv->v_type = VAR_STRING;
36483649
rettv->vval.v_string = NULL;
36493650
#ifdef FEAT_FOLDING
3651+
if (entered)
3652+
return; /* reject recursive use */
3653+
entered = TRUE;
3654+
36503655
lnum = get_tv_lnum(argvars);
36513656
/* treat illegal types and illegal string values for {lnum} the same */
36523657
if (lnum < 0)
@@ -3660,6 +3665,8 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
36603665
text = vim_strsave(text);
36613666
rettv->vval.v_string = text;
36623667
}
3668+
3669+
entered = FALSE;
36633670
#endif
36643671
}
36653672

src/testdir/test_fold.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func Test_move_folds_around_manual()
278278
call assert_equal(0, foldlevel(6))
279279
call assert_equal(9, foldclosedend(7))
280280
call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)'))
281+
281282
%d
282283
" Ensure moving around the edges still works.
283284
call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
@@ -446,3 +447,16 @@ func Test_fold_error()
446447
set foldmethod&
447448
bw!
448449
endfunc
450+
451+
func Test_foldtext_recursive()
452+
new
453+
call setline(1, ['{{{', 'some text', '}}}'])
454+
setlocal foldenable foldmethod=marker foldtext=foldtextresult(v\:foldstart)
455+
" This was crashing because of endless recursion.
456+
2foldclose
457+
redraw
458+
call assert_equal(1, foldlevel(2))
459+
call assert_equal(1, foldclosed(2))
460+
call assert_equal(3, foldclosedend(2))
461+
bwipe!
462+
endfunc

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1115,
772774
/**/
773775
1114,
774776
/**/

0 commit comments

Comments
 (0)