comparison src/move.c @ 35181:8b20000e3d18 v9.1.0413

patch 9.1.0413: smoothscroll may cause infinite loop Commit: https://github.com/vim/vim/commit/eff20eb35d2dba413c6d115291dd9ddea705e802 Author: Christian Brabandt <cb@256bit.org> Date: Wed May 15 21:35:36 2024 +0200 patch 9.1.0413: smoothscroll may cause infinite loop Problem: smoothscroll may cause infinite loop, with very narrow windows (Jaehwang Jung, after v9.1.0280) Solution: Check for width1 being negative, verify that win_linetabsize does not overflow fixes: #14750 closes: #14772 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 15 May 2024 21:45:05 +0200
parents 08f7c9428f82
children de9a4c63e943
comparison
equal deleted inserted replaced
35180:7b23db7ca750 35181:8b20000e3d18
1628 long so = get_scrolloff_value(); 1628 long so = get_scrolloff_value();
1629 int width1 = curwin->w_width - curwin_col_off(); 1629 int width1 = curwin->w_width - curwin_col_off();
1630 int width2 = width1 + curwin_col_off2(); 1630 int width2 = width1 + curwin_col_off2();
1631 int so_cols = so == 0 ? 0 : width1 + (so - 1) * width2; 1631 int so_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
1632 int space_cols = (curwin->w_height - 1) * width2; 1632 int space_cols = (curwin->w_height - 1) * width2;
1633 int overlap, top, bot;
1633 int size = so == 0 ? 0 : win_linetabsize(curwin, curwin->w_topline, 1634 int size = so == 0 ? 0 : win_linetabsize(curwin, curwin->w_topline,
1634 ml_get(curwin->w_topline), (colnr_T)MAXCOL); 1635 ml_get(curwin->w_topline), (colnr_T)MAXCOL);
1635 1636
1636 if (curwin->w_topline == 1 && curwin->w_skipcol == 0) 1637 if (curwin->w_topline == 1 && curwin->w_skipcol == 0)
1637 so_cols = 0; // Ignore 'scrolloff' at top of buffer. 1638 so_cols = 0; // Ignore 'scrolloff' at top of buffer.
1638 else if (so_cols > space_cols / 2) 1639 else if (so_cols > space_cols / 2)
1639 so_cols = space_cols / 2; // Not enough room: put cursor in the middle. 1640 so_cols = space_cols / 2; // Not enough room: put cursor in the middle.
1640 1641
1641 // Not enough screen lines in topline: ignore 'scrolloff'. 1642 // Not enough screen lines in topline: ignore 'scrolloff'.
1642 while (so_cols > size && so_cols - width2 >= width1) 1643 while (so_cols > size && so_cols - width2 >= width1 && width1 > 0)
1643 so_cols -= width2; 1644 so_cols -= width2;
1644 if (so_cols >= width1 && so_cols > size) 1645 if (so_cols >= width1 && so_cols > size)
1645 so_cols -= width1; 1646 so_cols -= width1;
1646 1647
1647 // If there is no marker or we have non-zero scrolloff, just ignore it. 1648 // If there is no marker or we have non-zero scrolloff, just ignore it.
1648 int overlap = (curwin->w_skipcol == 0 || so_cols != 0) ? 0 1649 overlap = (curwin->w_skipcol == 0 || so_cols != 0) ? 0
1649 : sms_marker_overlap(curwin, -1); 1650 : sms_marker_overlap(curwin, -1);
1650 int top = curwin->w_skipcol + overlap + so_cols; 1651 top = curwin->w_skipcol + overlap + so_cols;
1651 int bot = curwin->w_skipcol + width1 + (curwin->w_height - 1) * width2 1652 bot = curwin->w_skipcol + width1 + (curwin->w_height - 1) * width2
1652 - so_cols; 1653 - so_cols;
1653 validate_virtcol(); 1654 validate_virtcol();
1654 colnr_T col = curwin->w_virtcol; 1655 colnr_T col = curwin->w_virtcol;
1655 1656
1656 if (col < top) 1657 if (col < top)