summaryrefslogtreecommitdiffstats
path: root/src/fold.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-08-19 22:48:30 +0200
committerBram Moolenaar <Bram@vim.org>2019-08-19 22:48:30 +0200
commit9a4a8c4d5993c6371486c895a515c2ad351e9aaa (patch)
tree8edb7b29042b5c89c345c5df3220f715eeecf39b /src/fold.c
parentea7ecfe2a08877f98edec9b9c26b9e1b3673f00b (diff)
patch 8.1.1890: ml_get error when deleting fold markerv8.1.1890
Problem: Ml_get error when deleting fold marker. Solution: Check that the line number is not below the last line. Adjust the fold when deleting the empty line. (Christian Brabandt, closes #4834)
Diffstat (limited to 'src/fold.c')
-rw-r--r--src/fold.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/fold.c b/src/fold.c
index 4cc7a477d7..482d3c9682 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1813,7 +1813,7 @@ deleteFoldMarkers(
/*
* 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
+ * If the marker is not found, there is no error message. Could be a missing
* close-marker.
*/
static void
@@ -1826,6 +1826,9 @@ foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
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;
line = ml_get(lnum);
for (p = line; *p != NUL; ++p)
if (STRNCMP(p, marker, markerlen) == 0)
@@ -2733,16 +2736,19 @@ 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 = MAYBE;
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);