diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-07-05 20:17:22 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-07-05 20:17:22 +0200 |
commit | 437a746b4c1bd65cecc2e9095e911b58b13fce77 (patch) | |
tree | d64d82a7a70877f944d8fb690f1a9d6f03ef9591 | |
parent | b4d9b893d3c7af24b5adf4ae0475ada32d36f5ad (diff) |
patch 8.1.1636: crash when popup has fitting scrollbarv8.1.1636
Problem: Crash when popup has fitting scrollbar. (Trygve Aaberge)
Solution: Don't divide by zero if the scrollbar just fits. (closes #4615)
-rw-r--r-- | src/popupwin.c | 7 | ||||
-rw-r--r-- | src/testdir/test_popupwin.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/popupwin.c b/src/popupwin.c index 099a0c26a3..02aa83edad 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -2463,7 +2463,12 @@ update_popups(void (*win_update)(win_T *wp)) / linecount; if (sb_thumb_height == 0) sb_thumb_height = 1; - sb_thumb_top = (wp->w_topline - 1 + (linecount / wp->w_height) / 2) + if (linecount <= wp->w_height) + // it just fits, avoid divide by zero + sb_thumb_top = 0; + else + sb_thumb_top = (wp->w_topline - 1 + + (linecount / wp->w_height) / 2) * (wp->w_height - sb_thumb_height) / (linecount - wp->w_height); if (wp->w_scrollbar_highlight != NULL) diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index 4e798c6034..3983b5761a 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -1565,6 +1565,18 @@ func Test_popup_scrollbar() call delete('XtestPopupScroll') endfunc +func Test_popup_fitting_scrollbar() + " this was causing a crash, divide by zero + let winid = popup_create([ + \ 'one', 'two', 'longer line that wraps', 'four', 'five'], { + \ 'scrollbar': 1, + \ 'maxwidth': 10, + \ 'maxheight': 5, + \ 'firstline': 2}) + redraw + call popup_clear() +endfunc + func Test_popup_settext() if !CanRunVimInTerminal() throw 'Skipped: cannot make screendumps' diff --git a/src/version.c b/src/version.c index 634cd089b2..2c370da6b8 100644 --- a/src/version.c +++ b/src/version.c @@ -778,6 +778,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1636, +/**/ 1635, /**/ 1634, |