aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-14 07:02:45 +0800
committerGitHub <noreply@github.com>2023-01-14 07:02:45 +0800
commitb884d0b37031ec3d5a521925ea66621b572adfda (patch)
tree35b8710e6e1b2c31ee6faaa2bb744e86771feba4
parentfd3d30a22c2bcc7acd266214b761b44219aefbe7 (diff)
downloadrneovim-b884d0b37031ec3d5a521925ea66621b572adfda.tar.gz
rneovim-b884d0b37031ec3d5a521925ea66621b572adfda.tar.bz2
rneovim-b884d0b37031ec3d5a521925ea66621b572adfda.zip
vim-patch:9.0.1189: invalid memory access with folding and using "L" (#21787)
Problem: Invalid memory access with folding and using "L". Solution: Prevent the cursor from moving to line zero. https://github.com/vim/vim/commit/232bdaaca98c34a99ffadf27bf6ee08be6cc8f6a Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/normal.c4
-rw-r--r--src/nvim/testdir/test_fold.vim8
2 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 112ea5c1c6..cf5af66ddd 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -3645,7 +3645,9 @@ static void nv_scroll(cmdarg_T *cap)
&& curwin->w_cursor.lnum > curwin->w_topline; n--) {
(void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
- curwin->w_cursor.lnum--;
+ if (curwin->w_cursor.lnum > curwin->w_topline) {
+ curwin->w_cursor.lnum--;
+ }
}
} else {
curwin->w_cursor.lnum -= (linenr_T)cap->count1 - 1;
diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim
index f19e4c8253..130ad9c7e1 100644
--- a/src/nvim/testdir/test_fold.vim
+++ b/src/nvim/testdir/test_fold.vim
@@ -1475,4 +1475,12 @@ func Test_sort_closed_fold()
bwipe!
endfunc
+func Test_indent_with_L_command()
+ " The "L" command moved the cursor to line zero, causing the text saved for
+ " undo to use line number -1, which caused trouble for undo later.
+ new
+ sil! norm 8R V{zf8=Lu
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab