aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-25 20:09:23 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-25 20:48:21 +0800
commit771564b00e5b64ac74be443dde84e160bc7fce05 (patch)
tree95ee59485b9c1267044b763c5ff07c4b3e474a64
parent8543de3a862d55a762c130aa6a9d0e2a6c0b4838 (diff)
downloadrneovim-771564b00e5b64ac74be443dde84e160bc7fce05.tar.gz
rneovim-771564b00e5b64ac74be443dde84e160bc7fce05.tar.bz2
rneovim-771564b00e5b64ac74be443dde84e160bc7fce05.zip
vim-patch:8.2.5164: invalid memory access after diff buffer manipulations
Problem: Invalid memory access after diff buffer manipulations. Solution: Use zero offset when change removes all lines in a diff block. https://github.com/vim/vim/commit/c101abff4c6756db4f5e740fde289decb9452efa
-rw-r--r--src/nvim/diff.c6
-rw-r--r--src/nvim/testdir/test_diffmode.vim12
2 files changed, 14 insertions, 4 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 136fc5402b..55d8b7e36b 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -372,9 +372,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
// 2. 3. 4. 5.: inserted/deleted lines touching this diff.
if (deleted > 0) {
+ off = 0;
if (dp->df_lnum[idx] >= line1) {
- off = dp->df_lnum[idx] - lnum_deleted;
-
if (last <= line2) {
// 4. delete all lines of diff
if ((dp->df_next != NULL)
@@ -391,14 +390,13 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
dp->df_count[idx] = 0;
} else {
// 5. delete lines at or just before top of diff
+ off = dp->df_lnum[idx] - lnum_deleted;
n = off;
dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1;
check_unchanged = true;
}
dp->df_lnum[idx] = line1;
} else {
- off = 0;
-
if (last < line2) {
// 2. delete at end of diff
dp->df_count[idx] -= last - lnum_deleted + 1;
diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim
index 7ab8d0347b..3eabad28d0 100644
--- a/src/nvim/testdir/test_diffmode.vim
+++ b/src/nvim/testdir/test_diffmode.vim
@@ -1458,5 +1458,17 @@ func Test_diff_only()
%bwipe!
endfunc
+" This was causing invalid diff block values
+" FIXME: somehow this causes a valgrind error when run directly but not when
+" run as a test.
+func Test_diff_manipulations()
+ set diff
+ split 0
+ sil! norm R doobdeuR doobdeuR doobdeu
+
+ set nodiff
+ %bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab