neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2e055e49a3ae27db641986650aa9e7b2b962cf63
parent 0ca2d11c1f473d9924c261c9dbd4e38730932bb4
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue, 27 Jun 2023 08:55:59 +0800

Merge pull request #24170 from zeertzjq/vim-9.0.1664

vim-patch:9.0.{1664,1667}: divide by zero when scrolling with 'smoothscroll' set
Diffstat:
Msrc/nvim/move.c | 22++++++++++++----------
Mtest/functional/legacy/scroll_opt_spec.lua | 43+++++++++++++++++++++++++++++++++++++++++++
Mtest/old/testdir/test_scroll_opt.vim | 22++++++++++++++++++++++
3 files changed, 77 insertions(+), 10 deletions(-)

diff --git a/src/nvim/move.c b/src/nvim/move.c @@ -1954,17 +1954,19 @@ void scroll_cursor_bot(int min_scroll, int set_topbot) int top_plines = plines_win_nofill(curwin, curwin->w_topline, false); int skip_lines = 0; int width1 = curwin->w_width_inner - curwin_col_off(); - int width2 = width1 + curwin_col_off2(); - // similar formula is used in curs_columns() - if (curwin->w_skipcol > width1) { - skip_lines += (curwin->w_skipcol - width1) / width2 + 1; - } else if (curwin->w_skipcol > 0) { - skip_lines = 1; - } + if (width1 > 0) { + int width2 = width1 + curwin_col_off2(); + // similar formula is used in curs_columns() + if (curwin->w_skipcol > width1) { + skip_lines += (curwin->w_skipcol - width1) / width2 + 1; + } else if (curwin->w_skipcol > 0) { + skip_lines = 1; + } - top_plines -= skip_lines; - if (top_plines > curwin->w_height_inner) { - scrolled += (top_plines - curwin->w_height_inner); + top_plines -= skip_lines; + if (top_plines > curwin->w_height_inner) { + scrolled += (top_plines - curwin->w_height_inner); + } } } } diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua @@ -939,6 +939,49 @@ describe('smoothscroll', function() ]]) end) + -- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot() + it('does not divide by zero in zero-width window', function() + screen:try_resize(40, 19) + screen:set_default_attr_ids({ + [1] = {foreground = Screen.colors.Brown}; -- LineNr + [2] = {bold = true, foreground = Screen.colors.Blue}; -- NonText + [3] = {bold = true, reverse = true}; -- StatusLine + [4] = {reverse = true}; -- StatusLineNC + }) + exec([[ + silent normal yy + silent normal 19p + set cpoptions+=n + vsplit + vertical resize 0 + set foldcolumn=1 + set number + set smoothscroll + silent normal 20G + ]]) + screen:expect([[ + {1: }│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:@}│ | + {2:^@}│ | + {3:< }{4:[No Name] [+] }| + | + ]]) + end) + it("works with virt_lines above and below", function() screen:try_resize(55, 7) exec([=[ diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim @@ -836,4 +836,26 @@ func Test_smoothscroll_multi_skipcol() call StopVimInTerminal(buf) endfunc +" this was dividing by zero bug in scroll_cursor_bot +func Test_smoothscroll_zero_width_scroll_cursor_bot() + CheckScreendump + + let lines =<< trim END + silent normal yy + silent normal 19p + set cpoptions+=n + vsplit + vertical resize 0 + set foldcolumn=1 + set number + set smoothscroll + silent normal 20G + END + call writefile(lines, 'XSmoothScrollZeroBot', 'D') + let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19}) + call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {}) + + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab