]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2159: screenpos() may crash with neg. column v9.0.2159
authorzeertzjq <zeertzjq@outlook.com>
Tue, 12 Dec 2023 15:43:44 +0000 (16:43 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 12 Dec 2023 15:43:44 +0000 (16:43 +0100)
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>
src/move.c
src/testdir/test_cursor_func.vim
src/version.c

index fbb352a32e15af3b640fb036de033a2ed103adca..861d84b84e33712ce18f27660100ce8d07dd2905 100644 (file)
@@ -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);
 
index 3cdf4cb7f946428f0320327063a3ac9b43daa0e7..2bdda869e617490897f2ae4deaa7c683127ebd6b 100644 (file)
@@ -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()
index 4bb1c90bae4753714f9b553c0f260d6dee7ff247..15ff51dd72022e9f8354a5247b9922881b53c480 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2159,
 /**/
     2158,
 /**/