Skip to content

Commit

Permalink
patch 9.0.2159: screenpos() may crash with neg. column
Browse files Browse the repository at this point in the history
Problem:  screenpos() may crash with neg. column
Solution: validate and correct column

closes: #13669

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
zeertzjq authored and chrisbra committed Dec 12, 2023
1 parent a40e168 commit ec54af4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ f_screenpos(typval_T *argvars UNUSED, typval_T *rettv)
return;
}
pos.col = tv_get_number(&argvars[2]) - 1;
if (pos.col < 0)
pos.col = 0;
pos.coladd = 0;
textpos2screenpos(wp, &pos, &row, &scol, &ccol, &ecol);

Expand Down
5 changes: 5 additions & 0 deletions src/testdir/test_cursor_func.vim
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func Test_screenpos()
nmenu WinBar.TEST :
call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
nunmenu WinBar.TEST
call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))

call assert_equal(#{col: 0, row: 0, endcol: 0, curscol: 0}, screenpos(0, 0, 1))
call assert_equal(#{col: 0, row: 0, endcol: 0, curscol: 0}, screenpos(0, -1, 1))
call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(0, 1, -v:maxcol))
endfunc

func Test_screenpos_fold()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2159,
/**/
2158,
/**/
Expand Down

0 comments on commit ec54af4

Please sign in to comment.