# HG changeset patch # User Bram Moolenaar # Date 1605029403 -3600 # Node ID b05cfda397dc128759310e87f842356a36763f83 # Parent cd13664ff526f88f67fef96464188d0d9d9cc0ab patch 8.2.1972: crash when recreating nested fold Commit: https://github.com/vim/vim/commit/5e1f22ff614821b8fc7294c9dd22765acd403aeb Author: Bram Moolenaar Date: Tue Nov 10 18:23:52 2020 +0100 patch 8.2.1972: crash when recreating nested fold Problem: Crash when recreating nested fold. Solution: Check for empty growarray. (closes https://github.com/vim/vim/issues/7278) diff --git a/src/fold.c b/src/fold.c --- a/src/fold.c +++ b/src/fold.c @@ -640,7 +640,10 @@ foldCreate(linenr_T start, linenr_T end) break; } } - i = (int)(fp - (fold_T *)gap->ga_data); + if (gap->ga_len == 0) + i = 0; + else + i = (int)(fp - (fold_T *)gap->ga_data); } if (ga_grow(gap, 1) == OK) diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -844,4 +844,14 @@ func Test_move_no_folds() bwipe! endfunc +" this was crashing +func Test_fold_create_delete_create() + new + fold + fold + normal zd + fold + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1972, +/**/ 1971, /**/ 1970,