aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fold.c
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-08-20 04:52:56 +0200
committerGitHub <noreply@github.com>2019-08-20 04:52:56 +0200
commit57e19ea846ac2821e308029b4569cffa0a1fd41f (patch)
tree2652377de856c61c603ca2df9ff75a2ed3e64dd0 /src/nvim/fold.c
parent7fa49627e583e1020919760ad37cf4c1639469da (diff)
parentec9b57cb6e6679b7f08001677fc523a5d0a2a819 (diff)
downloadrneovim-57e19ea846ac2821e308029b4569cffa0a1fd41f.tar.gz
rneovim-57e19ea846ac2821e308029b4569cffa0a1fd41f.tar.bz2
rneovim-57e19ea846ac2821e308029b4569cffa0a1fd41f.zip
Merge pull request #10814 from janlazo/vim-8.1.1887
vim-patch:8.1.{1887,1890}
Diffstat (limited to 'src/nvim/fold.c')
-rw-r--r--src/nvim/fold.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index ad0bfe29e2..5ce953e626 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1645,19 +1645,22 @@ deleteFoldMarkers(
foldendmarkerlen);
}
-/* foldDelMarker() {{{2 */
-/*
- * Delete marker "marker[markerlen]" at the end of line "lnum".
- * Delete 'commentstring' if it matches.
- * If the marker is not found, there is no error message. Could a missing
- * close-marker.
- */
+// foldDelMarker() {{{2
+//
+// Delete marker "marker[markerlen]" at the end of line "lnum".
+// Delete 'commentstring' if it matches.
+// If the marker is not found, there is no error message. Could be a missing
+// close-marker.
static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen)
{
char_u *newline;
char_u *cms = curbuf->b_p_cms;
char_u *cms2;
+ // end marker may be missing and fold extends below the last line
+ if (lnum > curbuf->b_ml.ml_line_count) {
+ return;
+ }
char_u *line = ml_get(lnum);
for (char_u *p = line; *p != NUL; ++p) {
if (STRNCMP(p, marker, markerlen) != 0) {
@@ -2426,15 +2429,18 @@ static linenr_T foldUpdateIEMSRecurse(
* lvl >= level: fold continues below "bot"
*/
- /* Current fold at least extends until lnum. */
+ // Current fold at least extends until lnum.
if (fp->fd_len < flp->lnum - fp->fd_top) {
fp->fd_len = flp->lnum - fp->fd_top;
fp->fd_small = kNone;
fold_changed = true;
+ } else if (fp->fd_top + fp->fd_len > linecount) {
+ // running into the end of the buffer (deleted last line)
+ fp->fd_len = linecount - fp->fd_top + 1;
}
- /* Delete contained folds from the end of the last one found until where
- * we stopped looking. */
+ // Delete contained folds from the end of the last one found until where
+ // we stopped looking.
foldRemove(&fp->fd_nested, startlnum2 - fp->fd_top,
flp->lnum - 1 - fp->fd_top);