Skip to content

Commit 437a746

Browse files
committed
patch 8.1.1636: crash when popup has fitting scrollbar
Problem: Crash when popup has fitting scrollbar. (Trygve Aaberge) Solution: Don't divide by zero if the scrollbar just fits. (closes #4615)
1 parent b4d9b89 commit 437a746

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/popupwin.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,12 @@ update_popups(void (*win_update)(win_T *wp))
24632463
/ linecount;
24642464
if (sb_thumb_height == 0)
24652465
sb_thumb_height = 1;
2466-
sb_thumb_top = (wp->w_topline - 1 + (linecount / wp->w_height) / 2)
2466+
if (linecount <= wp->w_height)
2467+
// it just fits, avoid divide by zero
2468+
sb_thumb_top = 0;
2469+
else
2470+
sb_thumb_top = (wp->w_topline - 1
2471+
+ (linecount / wp->w_height) / 2)
24672472
* (wp->w_height - sb_thumb_height)
24682473
/ (linecount - wp->w_height);
24692474
if (wp->w_scrollbar_highlight != NULL)

src/testdir/test_popupwin.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,18 @@ func Test_popup_scrollbar()
15651565
call delete('XtestPopupScroll')
15661566
endfunc
15671567

1568+
func Test_popup_fitting_scrollbar()
1569+
" this was causing a crash, divide by zero
1570+
let winid = popup_create([
1571+
\ 'one', 'two', 'longer line that wraps', 'four', 'five'], {
1572+
\ 'scrollbar': 1,
1573+
\ 'maxwidth': 10,
1574+
\ 'maxheight': 5,
1575+
\ 'firstline': 2})
1576+
redraw
1577+
call popup_clear()
1578+
endfunc
1579+
15681580
func Test_popup_settext()
15691581
if !CanRunVimInTerminal()
15701582
throw 'Skipped: cannot make screendumps'

src/version.c

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

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1636,
780782
/**/
781783
1635,
782784
/**/

0 commit comments

Comments
 (0)