changeset 22850:b05cfda397dc v8.2.1972

patch 8.2.1972: crash when recreating nested fold Commit: https://github.com/vim/vim/commit/5e1f22ff614821b8fc7294c9dd22765acd403aeb Author: Bram Moolenaar <Bram@vim.org> 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)
author Bram Moolenaar <Bram@vim.org>
date Tue, 10 Nov 2020 18:30:03 +0100
parents cd13664ff526
children 86edcfa72e2a
files src/fold.c src/testdir/test_fold.vim src/version.c
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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
--- 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,