Skip to content

Commit 8154e64

Browse files
fullwaywangbrammool
authored andcommitted
patch 9.0.1664: divide by zero when scrolling with 'smoothscroll' set
Problem: Divide by zero when scrolling with 'smoothscroll' set. Solution: Avoid using a negative width. (closes #12540, closes #12528)
1 parent c9a4a8a commit 8154e64

4 files changed

Lines changed: 58 additions & 10 deletions

File tree

src/move.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,17 +2591,20 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
25912591
(curwin, curwin->w_topline, FALSE);
25922592
int skip_lines = 0;
25932593
int width1 = curwin->w_width - curwin_col_off();
2594-
int width2 = width1 + curwin_col_off2();
2595-
// similar formula is used in curs_columns()
2596-
if (curwin->w_skipcol > width1)
2597-
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
2598-
else if (curwin->w_skipcol > 0)
2599-
skip_lines = 1;
2600-
2601-
top_plines -= skip_lines;
2602-
if (top_plines > curwin->w_height)
2594+
if (width1 > 0)
26032595
{
2604-
scrolled += (top_plines - curwin->w_height);
2596+
int width2 = width1 + curwin_col_off2();
2597+
// similar formula is used in curs_columns()
2598+
if (curwin->w_skipcol > width1)
2599+
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
2600+
else if (curwin->w_skipcol > 0)
2601+
skip_lines = 1;
2602+
2603+
top_plines -= skip_lines;
2604+
if (top_plines > curwin->w_height)
2605+
{
2606+
scrolled += (top_plines - curwin->w_height);
2607+
}
26052608
}
26062609
}
26072610
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
| +0#af5f00255#ffffff0||+1#0000000&| +0&&@9
2+
|@+0#4040ff13&||+1#0000000&| +0&&@9
3+
|@+0#4040ff13&||+1#0000000&| +0&&@9
4+
|@+0#4040ff13&||+1#0000000&| +0&&@9
5+
|@+0#4040ff13&||+1#0000000&| +0&&@9
6+
|@+0#4040ff13&||+1#0000000&| +0&&@9
7+
|@+0#4040ff13&||+1#0000000&| +0&&@9
8+
|@+0#4040ff13&||+1#0000000&| +0&&@9
9+
|@+0#4040ff13&||+1#0000000&| +0&&@9
10+
|@+0#4040ff13&||+1#0000000&| +0&&@9
11+
|@+0#4040ff13&||+1#0000000&| +0&&@9
12+
|@+0#4040ff13&||+1#0000000&| +0&&@9
13+
|@+0#4040ff13&||+1#0000000&| +0&&@9
14+
|@+0#4040ff13&||+1#0000000&| +0&&@9
15+
|@+0#4040ff13&||+1#0000000&| +0&&@9
16+
|@+0#4040ff13&||+1#0000000&| +0&&@9
17+
>@+0#4040ff13&||+1#0000000&| +0&&@9
18+
|<+3&&| |<+1&&|a|m|e|]| |[|+|]|
19+
| +0&&@11

src/testdir/test_scroll_opt.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,4 +833,28 @@ func Test_smoothscroll_multi_skipcol()
833833
call StopVimInTerminal(buf)
834834
endfunc
835835

836+
" this was dividing by zero bug in scroll_cursor_bot
837+
func Test_smoothscroll_zero_width_scroll_cursor_bot()
838+
CheckScreendump
839+
840+
let lines =<< trim END
841+
silent normal yy
842+
silent normal 19p
843+
winsize 0 19
844+
vsplit
845+
vertical resize 0
846+
set foldcolumn=1
847+
set number
848+
set smoothscroll
849+
silent normal 20G
850+
END
851+
call writefile(lines, 'XSmoothScrollZeroBot', 'D')
852+
let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19, wait_for_ruler: 0})
853+
call TermWait(buf, 1000)
854+
855+
call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
856+
857+
call StopVimInTerminal(buf)
858+
endfunc
859+
836860
" 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+
1664,
698700
/**/
699701
1663,
700702
/**/

0 commit comments

Comments
 (0)