Skip to content

Commit dd9ed46

Browse files
ychinchrisbra
authored andcommitted
patch 9.1.1823: diff: w_topline may be invalidated
Problem: diff: w_topline may be invalidated Solution: Update lnum in diff_set_topline() (Yee Cheng Chin). This can happen in ex_diffupdate() for certain edge cases which cause the logic to now be wrong. This was also the root cause for #18437 where Vim would crash due to a null pointer dereferencing (said pointer would not be null under normal circumstances). related: #18437 closes: #18484 Signed-off-by: Yee Cheng Chin <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent ae3a866 commit dd9ed46

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ calculate_topfill_and_topline(
22542254

22552255
// move the same amount of virtual lines in the target buffer to find the
22562256
// cursor's line number
2257-
if (thistopdiff != NULL)
2257+
if (thistopdiff != NULL) // this should not be null, but just for safety
22582258
curlinenum_to = thistopdiff->df_lnum[toidx];
22592259

22602260
int virt_lines_left = virtual_lines_passed;
@@ -2681,7 +2681,7 @@ diff_check_fill(win_T *wp, linenr_T lnum)
26812681
diff_set_topline(win_T *fromwin, win_T *towin)
26822682
{
26832683
buf_T *frombuf = fromwin->w_buffer;
2684-
linenr_T lnum = fromwin->w_topline;
2684+
linenr_T lnum;
26852685
int fromidx;
26862686
int toidx;
26872687
diff_T *dp;
@@ -2693,6 +2693,7 @@ diff_set_topline(win_T *fromwin, win_T *towin)
26932693
if (curtab->tp_diff_invalid)
26942694
ex_diffupdate(NULL); // update after a big change
26952695

2696+
lnum = fromwin->w_topline;
26962697
towin->w_topfill = 0;
26972698

26982699
// search for a change that includes "lnum" in the list of diffblocks.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1823,
732734
/**/
733735
1822,
734736
/**/

0 commit comments

Comments
 (0)