]> granicus.if.org Git - vim/commitdiff
patch 8.2.1972: crash when recreating nested fold v8.2.1972
authorBram Moolenaar <Bram@vim.org>
Tue, 10 Nov 2020 17:23:52 +0000 (18:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 10 Nov 2020 17:23:52 +0000 (18:23 +0100)
Problem:    Crash when recreating nested fold.
Solution:   Check for empty growarray. (closes #7278)

src/fold.c
src/testdir/test_fold.vim
src/version.c

index 4b4e6182997ee4c06ef2a3d3ff3f6ba3a20a26c3..82ce7e707de3e4bb6f9afcea8beda1096c0acef7 100644 (file)
@@ -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)
index f0bd6e481dc4ef9623d1fd6e2383b9e5edd86157..1377983ca1dba159f6b73e981e1370076e8fa18a 100644 (file)
@@ -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
index 91477bcef2b73734a59d6f4659cd32e17f796039..e2affa79ed463cc7f5c0b9be824b09745951d307 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1972,
 /**/
     1971,
 /**/