]> granicus.if.org Git - vim/commitdiff
patch 8.1.1636: crash when popup has fitting scrollbar v8.1.1636
authorBram Moolenaar <Bram@vim.org>
Fri, 5 Jul 2019 18:17:22 +0000 (20:17 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 5 Jul 2019 18:17:22 +0000 (20:17 +0200)
Problem:    Crash when popup has fitting scrollbar. (Trygve Aaberge)
Solution:   Don't divide by zero if the scrollbar just fits. (closes #4615)

src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index 099a0c26a339c9a4d18201707244ef1495d26e30..02aa83edad1396939d8a0c92c01f0dc7e1f96cee 100644 (file)
@@ -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)
index 4e798c60344a7d1d5e1ff16c3cd1f52c0394e84c..3983b5761a417e00ccdfae84c5b1deea228cc469 100644 (file)
@@ -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'
index 634cd089b24bb6b5e657ef395f09e16e7f363180..2c370da6b875228df62e9a2822823e064860d535 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1636,
 /**/
     1635,
 /**/