diff options
author | James McCoy <jamessan@jamessan.com> | 2020-09-03 23:04:38 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2020-09-04 08:25:25 -0400 |
commit | ae8f10873291bd35421d5d910154d9750779747e (patch) | |
tree | a8bb5deaec1c487f1fd6dad05a01bf1474a47913 /src | |
parent | 0c851e5226784db7809e4cb050148b9121af11d7 (diff) | |
download | rneovim-ae8f10873291bd35421d5d910154d9750779747e.tar.gz rneovim-ae8f10873291bd35421d5d910154d9750779747e.tar.bz2 rneovim-ae8f10873291bd35421d5d910154d9750779747e.zip |
vim-patch:8.2.1553: crash in edit test
Problem: Crash in edit test.
Solution: Avoid using invalid pointer.
https://github.com/vim/vim/commit/2c93c685e3334c50d9a748ad699df727a4501b08
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/fold.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c index dd13938836..3d631a158e 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -573,31 +573,35 @@ void foldCreate(win_T *wp, linenr_T start, linenr_T end) // Find the place to insert the new fold gap = &wp->w_folds; - for (;; ) { - if (!foldFind(gap, start_rel, &fp)) - break; - if (fp->fd_top + fp->fd_len > end_rel) { - /* New fold is completely inside this fold: Go one level deeper. */ - gap = &fp->fd_nested; - start_rel -= fp->fd_top; - end_rel -= fp->fd_top; - if (use_level || fp->fd_flags == FD_LEVEL) { - use_level = true; - if (level >= wp->w_p_fdl) { + if (gap->ga_len == 0) { + i = 0; + } else { + for (;;) { + if (!foldFind(gap, start_rel, &fp)) + break; + if (fp->fd_top + fp->fd_len > end_rel) { + /* New fold is completely inside this fold: Go one level deeper. */ + gap = &fp->fd_nested; + start_rel -= fp->fd_top; + end_rel -= fp->fd_top; + if (use_level || fp->fd_flags == FD_LEVEL) { + use_level = true; + if (level >= wp->w_p_fdl) { + closed = true; + } + } else if (fp->fd_flags == FD_CLOSED) { closed = true; } - } else if (fp->fd_flags == FD_CLOSED) { - closed = true; + level++; + } else { + /* This fold and new fold overlap: Insert here and move some folds + * inside the new fold. */ + break; } - level++; - } else { - /* This fold and new fold overlap: Insert here and move some folds - * inside the new fold. */ - break; } + i = (int)(fp - (fold_T *)gap->ga_data); } - i = (int)(fp - (fold_T *)gap->ga_data); ga_grow(gap, 1); { fp = (fold_T *)gap->ga_data + i; |