Skip to content

Commit 870219c

Browse files
committed
patch 9.0.1247: divide by zero with 'smoothscroll' set and a narrow window
Problem: Divide by zero with 'smoothscroll' set and a narrow window. Solution: Bail out when the window is too narrow.
1 parent 142ed77 commit 870219c

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/move.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,9 @@ adjust_skipcol(void)
19331933
return;
19341934

19351935
int width1 = curwin->w_width - curwin_col_off();
1936+
if (width1 <= 0)
1937+
return; // no text will be displayed
1938+
19361939
int width2 = width1 + curwin_col_off2();
19371940
long so = get_scrolloff_value();
19381941
int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
> +0&#ffffff0@59
2+
@60
3+
@60
4+
@60
5+
@60
6+
@60
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|:+0&#ffffff0|s|i|l| |n|o|r|m| |^|W|^|N| @45
2+
> @59
3+
@60
4+
@60
5+
@60
6+
@60

src/testdir/test_scroll_opt.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,5 +560,32 @@ func Test_smoothscroll_mouse_pos()
560560
let &ttymouse = save_ttymouse
561561
endfunc
562562

563+
" this was dividing by zero
564+
func Test_smoothscrol_zero_width()
565+
CheckScreendump
566+
567+
let lines =<< trim END
568+
winsize 0 0
569+
vsplit
570+
vsplit
571+
vsplit
572+
vsplit
573+
vsplit
574+
sil norm H
575+
set wrap
576+
set smoothscroll
577+
set number
578+
END
579+
call writefile(lines, 'XSmoothScrollZero', 'D')
580+
let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
581+
call TermWait(buf, 3000)
582+
call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
583+
584+
call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
585+
call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
586+
587+
call StopVimInTerminal(buf)
588+
endfunc
589+
563590

564591
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1247,
698700
/**/
699701
1246,
700702
/**/

0 commit comments

Comments
 (0)