]> granicus.if.org Git - vim/commitdiff
patch 9.0.1247: divide by zero with 'smoothscroll' set and a narrow window v9.0.1247
authorBram Moolenaar <Bram@vim.org>
Thu, 26 Jan 2023 14:14:43 +0000 (14:14 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 26 Jan 2023 14:14:43 +0000 (14:14 +0000)
Problem:    Divide by zero with 'smoothscroll' set and a narrow window.
Solution:   Bail out when the window is too narrow.

src/move.c
src/testdir/dumps/Test_smoothscroll_zero_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_smoothscroll_zero_2.dump [new file with mode: 0644]
src/testdir/test_scroll_opt.vim
src/version.c

index d3648df8b62ec387e80eb464907b5efc49fbeec9..3c50d258c56335ba8edc13bc4361529dedae9375 100644 (file)
@@ -1933,6 +1933,9 @@ adjust_skipcol(void)
        return;
 
     int            width1 = curwin->w_width - curwin_col_off();
+    if (width1 <= 0)
+       return;  // no text will be displayed
+
     int            width2 = width1 + curwin_col_off2();
     long    so = get_scrolloff_value();
     int            scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
diff --git a/src/testdir/dumps/Test_smoothscroll_zero_1.dump b/src/testdir/dumps/Test_smoothscroll_zero_1.dump
new file mode 100644 (file)
index 0000000..5a99f57
--- /dev/null
@@ -0,0 +1,6 @@
+> +0&#ffffff0@59
+@60
+@60
+@60
+@60
+@60
diff --git a/src/testdir/dumps/Test_smoothscroll_zero_2.dump b/src/testdir/dumps/Test_smoothscroll_zero_2.dump
new file mode 100644 (file)
index 0000000..1879381
--- /dev/null
@@ -0,0 +1,6 @@
+|:+0&#ffffff0|s|i|l| |n|o|r|m| |^|W|^|N| @45
+> @59
+@60
+@60
+@60
+@60
index 2fa91682d8d1dfe4ad5070968a5c515c74301c1d..58344f9a925cf13a274898615fce3f3b3d221e74 100644 (file)
@@ -560,5 +560,32 @@ func Test_smoothscroll_mouse_pos()
   let &ttymouse = save_ttymouse
 endfunc
 
+" this was dividing by zero
+func Test_smoothscrol_zero_width()
+  CheckScreendump
+
+  let lines =<< trim END
+      winsize 0 0
+      vsplit
+      vsplit
+      vsplit
+      vsplit
+      vsplit
+      sil norm \17\ e\17H
+      set wrap
+      set smoothscroll
+      set number
+  END
+  call writefile(lines, 'XSmoothScrollZero', 'D')
+  let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
+  call TermWait(buf, 3000)
+  call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
+
+  call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
+  call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 12f444a8c70a5a36bf04d3be4bb4e883228ed82e..79f021b9661e98f4c52fe422faa1b69de7617fee 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1247,
 /**/
     1246,
 /**/