mirror of
https://github.com/vim/vim.git
synced 2025-08-22 19:27:53 -04:00
patch 8.0.1115: crash when using foldtextresult() recursively
Problem: Crash when using foldtextresult() recursively. Solution: Avoid recursive calls. (Yasuhiro Matsumoto, closes #2098)
This commit is contained in:
parent
4cf56bbc85
commit
495b7dd213
@ -3642,11 +3642,16 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
char_u buf[FOLD_TEXT_LEN];
|
char_u buf[FOLD_TEXT_LEN];
|
||||||
foldinfo_T foldinfo;
|
foldinfo_T foldinfo;
|
||||||
int fold_count;
|
int fold_count;
|
||||||
|
static int entered = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
|
if (entered)
|
||||||
|
return; /* reject recursive use */
|
||||||
|
entered = TRUE;
|
||||||
|
|
||||||
lnum = get_tv_lnum(argvars);
|
lnum = get_tv_lnum(argvars);
|
||||||
/* treat illegal types and illegal string values for {lnum} the same */
|
/* treat illegal types and illegal string values for {lnum} the same */
|
||||||
if (lnum < 0)
|
if (lnum < 0)
|
||||||
@ -3660,6 +3665,8 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
text = vim_strsave(text);
|
text = vim_strsave(text);
|
||||||
rettv->vval.v_string = text;
|
rettv->vval.v_string = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entered = FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +278,7 @@ func Test_move_folds_around_manual()
|
|||||||
call assert_equal(0, foldlevel(6))
|
call assert_equal(0, foldlevel(6))
|
||||||
call assert_equal(9, foldclosedend(7))
|
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)'))
|
call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)'))
|
||||||
|
|
||||||
%d
|
%d
|
||||||
" Ensure moving around the edges still works.
|
" Ensure moving around the edges still works.
|
||||||
call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
|
call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
|
||||||
@ -446,3 +447,16 @@ func Test_fold_error()
|
|||||||
set foldmethod&
|
set foldmethod&
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
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
|
||||||
|
@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1115,
|
||||||
/**/
|
/**/
|
||||||
1114,
|
1114,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user