aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/diff.c
diff options
context:
space:
mode:
authorJonathon <32371757+jwhite510@users.noreply.github.com>2022-12-02 07:45:00 -0500
committerGitHub <noreply@github.com>2022-12-02 13:45:00 +0100
commitc95a0c99592e5bd17c630ea31618026ae6b5ea34 (patch)
tree0719407a68e2bf6955dd7d9d99a1fb14567aa5fb /src/nvim/diff.c
parent1145a9b2485a4e5072cffe28a958da983cd59e84 (diff)
downloadrneovim-c95a0c99592e5bd17c630ea31618026ae6b5ea34.tar.gz
rneovim-c95a0c99592e5bd17c630ea31618026ae6b5ea34.tar.bz2
rneovim-c95a0c99592e5bd17c630ea31618026ae6b5ea34.zip
fix(diff): fix a crash in diff mode with linematch enabled (#21070)
Problem: With two files open side by side in diff mode and deleting all of the contents of one file, the w_topfill value, which indicates the number of filler lines at the top of the window is set to be a negative number, and it will result in the virtual_lines_passed variable also being negative, and this while loop will run when it shouldn't. While calculating where the cursor and topline should be with linematch enabled, this topfill value is used to put the cursor and top line where it should be in the other windows. If that topfill number is negative, this causes a segfault. Solution: Check for positive top fill.
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r--src/nvim/diff.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 011632a4ef..c913260a80 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -1890,7 +1890,7 @@ static void count_filler_lines_and_topline(int *curlinenum_to, int *linesfiller,
const diff_T *curdif = thistopdiff;
int ch_virtual_lines = 0;
int isfiller = 0;
- while (virtual_lines_passed) {
+ while (virtual_lines_passed > 0) {
if (ch_virtual_lines) {
virtual_lines_passed--;
ch_virtual_lines--;