vim-patch:8.0.1115: crash when using foldtextresult() recursively (#8972)

Problem:    Crash when using foldtextresult() recursively.
Solution:   Avoid recursive calls. (Yasuhiro Matsumoto, closes vim/vim#2098)
495b7dd213
This commit is contained in:
Jan Edmund Lazo
2018-09-09 13:22:10 -04:00
committed by Justin M. Keyes
parent d47af7f10e
commit dd0dd4d78d
2 changed files with 21 additions and 0 deletions

View File

@@ -8872,9 +8872,14 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr)
char_u buf[FOLD_TEXT_LEN];
foldinfo_T foldinfo;
int fold_count;
static bool entered = false;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (entered) {
return; // reject recursive use
}
entered = true;
linenr_T lnum = tv_get_lnum(argvars);
// Treat illegal types and illegal string values for {lnum} the same.
if (lnum < 0) {
@@ -8888,6 +8893,8 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
rettv->vval.v_string = text;
}
entered = false;
}
/*

View File

@@ -278,6 +278,7 @@ func Test_move_folds_around_manual()
call assert_equal(0, foldlevel(6))
call assert_equal(9, foldclosedend(7))
call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)'))
%d
" Ensure moving around the edges still works.
call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
@@ -634,3 +635,16 @@ func Test_fold_move()
set fdm& sw& fdl&
enew!
endfunc
func Test_foldtext_recursive()
new
call setline(1, ['{{{', 'some text', '}}}'])
setlocal foldenable foldmethod=marker foldtext=foldtextresult(v\:foldstart)
" This was crashing because of endless recursion.
2foldclose
redraw
call assert_equal(1, foldlevel(2))
call assert_equal(1, foldclosed(2))
call assert_equal(3, foldclosedend(2))
bwipe!
endfunc