commit 8543de3a862d55a762c130aa6a9d0e2a6c0b4838
parent 611b43369e73b0da799226f70a6821c0c31ca222
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon, 25 Jul 2022 20:06:24 +0800
vim-patch:8.2.5163: crash when deleting buffers in diff mode
Problem: Crash when deleting buffers in diff mode.
Solution: Recompute diffs later. Skip window without a valid buffer.
https://github.com/vim/vim/commit/cd38bb4d83c942c4bad596835c6766cbf32e5195
Diffstat:
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
@@ -115,7 +115,10 @@ void diff_buf_delete(buf_T *buf)
tp->tp_diff_invalid = true;
if (tp == curtab) {
- diff_redraw(true);
+ // don't redraw right away, more might change or buffer state
+ // is invalid right now
+ need_diff_redraw = true;
+ redraw_later(curwin, VALID);
}
}
}
@@ -648,7 +651,8 @@ void diff_redraw(bool dofold)
need_diff_redraw = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- if (!wp->w_p_diff) {
+ // when closing windows or wiping buffers skip invalid window
+ if (!wp->w_p_diff || !buf_valid(wp->w_buffer)) {
continue;
}
redraw_later(wp, SOME_VALID);
diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim
@@ -1446,5 +1446,17 @@ func Test_diff_scroll()
call delete('Xright')
endfunc
+" This was trying to update diffs for a buffer being closed
+func Test_diff_only()
+ silent! lfile
+ set diff
+ lopen
+ norm o
+ silent! norm o
+
+ set nodiff
+ %bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab