Mercurial > vim
changeset 17274:6a7ba68d448e v8.1.1636
patch 8.1.1636: crash when popup has fitting scrollbar
commit https://github.com/vim/vim/commit/437a746b4c1bd65cecc2e9095e911b58b13fce77
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 5 20:17:22 2019 +0200
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 https://github.com/vim/vim/issues/4615)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 05 Jul 2019 20:30:07 +0200 |
parents | 25b99b296474 |
children | 1fc05146c373 |
files | src/popupwin.c src/testdir/test_popupwin.vim src/version.c |
diffstat | 3 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/popupwin.c +++ b/src/popupwin.c @@ -2463,7 +2463,12 @@ update_popups(void (*win_update)(win_T * / 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)
--- 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'