Skip to content

Commit 989a70c

Browse files
committed
patch 8.0.0948: crash if timer closes window while dragging status line
Problem: Crash if timer closes window while dragging status line. Solution: Check if the window still exists. (Yasuhiro Matsumoto, closes #1979)
1 parent 6fe15bb commit 989a70c

6 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/edit.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9418,7 +9418,7 @@ ins_mousescroll(int dir)
94189418
{
94199419
pos_T tpos;
94209420
# if defined(FEAT_WINDOWS)
9421-
win_T *old_curwin = curwin;
9421+
win_T *old_curwin = curwin, *wp;
94229422
# endif
94239423
# ifdef FEAT_INS_EXPAND
94249424
int did_scroll = FALSE;
@@ -9435,7 +9435,10 @@ ins_mousescroll(int dir)
94359435
col = mouse_col;
94369436

94379437
/* find the window at the pointer coordinates */
9438-
curwin = mouse_find_win(&row, &col);
9438+
wp = mouse_find_win(&row, &col);
9439+
if (wp == NULL)
9440+
return;
9441+
curwin = wp;
94399442
curbuf = curwin->w_buffer;
94409443
}
94419444
if (curwin == old_curwin)

src/evalfunc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,6 +4382,8 @@ f_getchar(typval_T *argvars, typval_T *rettv)
43824382
/* Find the window at the mouse coordinates and compute the
43834383
* text position. */
43844384
win = mouse_find_win(&row, &col);
4385+
if (win == NULL)
4386+
return;
43854387
(void)mouse_comp_pos(win, &row, &col, &lnum);
43864388
# ifdef FEAT_WINDOWS
43874389
for (wp = firstwin; wp != win; wp = wp->w_next)

src/gui.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4933,7 +4933,7 @@ gui_mouse_correct(void)
49334933
}
49344934

49354935
/*
4936-
* Find window where the mouse pointer "y" coordinate is in.
4936+
* Find window where the mouse pointer "x" / "y" coordinate is in.
49374937
*/
49384938
static win_T *
49394939
xy2win(int x UNUSED, int y UNUSED)
@@ -4948,6 +4948,8 @@ xy2win(int x UNUSED, int y UNUSED)
49484948
if (row < 0 || col < 0) /* before first window */
49494949
return NULL;
49504950
wp = mouse_find_win(&row, &col);
4951+
if (wp == NULL)
4952+
return NULL;
49514953
# ifdef FEAT_MOUSESHAPE
49524954
if (State == HITRETURN || State == ASKMORE)
49534955
{

src/normal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,7 +4627,7 @@ nv_screengo(oparg_T *oap, int dir, long dist)
46274627
nv_mousescroll(cmdarg_T *cap)
46284628
{
46294629
# ifdef FEAT_WINDOWS
4630-
win_T *old_curwin = curwin;
4630+
win_T *old_curwin = curwin, *wp;
46314631

46324632
if (mouse_row >= 0 && mouse_col >= 0)
46334633
{
@@ -4637,7 +4637,10 @@ nv_mousescroll(cmdarg_T *cap)
46374637
col = mouse_col;
46384638

46394639
/* find the window at the pointer coordinates */
4640-
curwin = mouse_find_win(&row, &col);
4640+
wp = mouse_find_win(&row, &col);
4641+
if (wp == NULL)
4642+
return;
4643+
curwin = wp;
46414644
curbuf = curwin->w_buffer;
46424645
}
46434646
# endif

src/ui.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,8 @@ jump_to_mouse(
27092709
#ifdef FEAT_WINDOWS
27102710
/* find the window where the row is in */
27112711
wp = mouse_find_win(&row, &col);
2712+
if (wp == NULL)
2713+
return IN_UNKNOWN;
27122714
#else
27132715
wp = firstwin;
27142716
#endif
@@ -3117,11 +3119,13 @@ mouse_comp_pos(
31173119
/*
31183120
* Find the window at screen position "*rowp" and "*colp". The positions are
31193121
* updated to become relative to the top-left of the window.
3122+
* Returns NULL when something is wrong.
31203123
*/
31213124
win_T *
31223125
mouse_find_win(int *rowp, int *colp UNUSED)
31233126
{
31243127
frame_T *fp;
3128+
win_T *wp;
31253129

31263130
fp = topframe;
31273131
*rowp -= firstwin->w_winrow;
@@ -3148,7 +3152,12 @@ mouse_find_win(int *rowp, int *colp UNUSED)
31483152
}
31493153
}
31503154
}
3151-
return fp->fr_win;
3155+
/* When using a timer that closes a window the window might not actually
3156+
* exist. */
3157+
FOR_ALL_WINDOWS(wp)
3158+
if (wp == fp->fr_win)
3159+
return wp;
3160+
return NULL;
31523161
}
31533162
#endif
31543163

@@ -3171,6 +3180,8 @@ get_fpos_of_mouse(pos_T *mpos)
31713180
#ifdef FEAT_WINDOWS
31723181
/* find the window where the row is in */
31733182
wp = mouse_find_win(&row, &col);
3183+
if (wp == NULL)
3184+
return IN_UNKNOWN;
31743185
#else
31753186
wp = firstwin;
31763187
#endif

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
948,
772774
/**/
773775
947,
774776
/**/

0 commit comments

Comments
 (0)