diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-05-11 11:23:37 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-05-11 11:23:37 +0200 |
commit | 031a745608d615d56f9d79bb0f76e2a74b2eaf14 (patch) | |
tree | 93fb1e4f968bbd3e4a08e18b6e5fa7dd98ac9b64 /src/mouse.c | |
parent | 1c5728e0c4a9df930879f9f0ca108092d5902194 (diff) |
patch 9.1.0406: Divide by zero with getmousepos() and 'smoothscroll'v9.1.0406
Problem: Divide by zero with getmousepos() and 'smoothscroll'.
Solution: Don't compute skip_lines when width1 is zero.
(zeertzjq)
closes: #14747
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/mouse.c')
-rw-r--r-- | src/mouse.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/mouse.c b/src/mouse.c index 247c6df8e2..4e10e723ed 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -3029,16 +3029,22 @@ mouse_comp_pos( 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 - win_col_off(win); - int skip_lines = 0; - if (win->w_skipcol > width1) - skip_lines = (win->w_skipcol - width1) + + 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; + else if (win->w_skipcol > 0) + skip_lines = 1; + + count -= skip_lines; + } } if (count > row) |