aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-05-11 17:46:22 +0800
committerGitHub <noreply@github.com>2024-05-11 17:46:22 +0800
commit14693353d566d126d1e8f28a8e6cbc10e27c09d1 (patch)
treebe4db24fbd50dc44d5a0f57a3b9c08b9c12038e3 /src
parent854c362cc88786b45e7c94a124c718dac0a03660 (diff)
downloadrneovim-14693353d566d126d1e8f28a8e6cbc10e27c09d1.tar.gz
rneovim-14693353d566d126d1e8f28a8e6cbc10e27c09d1.tar.bz2
rneovim-14693353d566d126d1e8f28a8e6cbc10e27c09d1.zip
vim-patch:9.1.0406: Divide by zero with getmousepos() and 'smoothscroll' (#28701)
Problem: Divide by zero with getmousepos() and 'smoothscroll'. Solution: Don't compute skip_lines when width1 is zero. (zeertzjq) closes: vim/vim#14747 https://github.com/vim/vim/commit/031a745608d615d56f9d79bb0f76e2a74b2eaf14
Diffstat (limited to 'src')
-rw-r--r--src/nvim/mouse.c21
-rw-r--r--src/nvim/move.c6
2 files changed, 17 insertions, 10 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 9d30d7d5ab..f393b0fd0f 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -1621,16 +1621,21 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
}
if (win->w_skipcol > 0 && lnum == win->w_topline) {
- // Adjust for 'smoothscroll' clipping the top screen lines.
- // A similar formula is used in curs_columns().
int width1 = win->w_width_inner - win_col_off(win);
- int skip_lines = 0;
- if (win->w_skipcol > width1) {
- skip_lines = (win->w_skipcol - width1) / (width1 + win_col_off2(win)) + 1;
- } else if (win->w_skipcol > 0) {
- skip_lines = 1;
+
+ if (width1 > 0) {
+ int skip_lines = 0;
+
+ // Adjust for 'smoothscroll' clipping the top screen lines.
+ // A similar formula is used in curs_columns().
+ if (win->w_skipcol > width1) {
+ skip_lines = (win->w_skipcol - width1) / (width1 + win_col_off2(win)) + 1;
+ } else if (win->w_skipcol > 0) {
+ skip_lines = 1;
+ }
+
+ count -= skip_lines;
}
- count -= skip_lines;
}
if (count > row) {
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 078ce3d72c..66667cecc4 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1974,11 +1974,13 @@ void scroll_cursor_bot(win_T *wp, int min_scroll, bool set_topbot)
// need to scroll the additional clipped lines to scroll past the
// top line before we can move on to the other lines.
int top_plines = plines_win_nofill(wp, wp->w_topline, false);
- int skip_lines = 0;
int width1 = wp->w_width_inner - win_col_off(wp);
+
if (width1 > 0) {
int width2 = width1 + win_col_off2(wp);
- // similar formula is used in curs_columns()
+ int skip_lines = 0;
+
+ // A similar formula is used in curs_columns().
if (wp->w_skipcol > width1) {
skip_lines += (wp->w_skipcol - width1) / width2 + 1;
} else if (wp->w_skipcol > 0) {