patch 9.0.2159: screenpos() may crash with neg. column

Commit: 
https://github.com/vim/vim/commit/ec54af4e26952d954a4cc009f62c80ea01445d30
Author: zeertzjq <[email protected]>
Date:   Tue Dec 12 16:43:44 2023 +0100

    patch 9.0.2159: screenpos() may crash with neg. column
    
    Problem:  screenpos() may crash with neg. column
    Solution: validate and correct column
    
    closes: #13669
    
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/move.c b/src/move.c
index fbb352a32..861d84b84 100644
--- a/src/move.c
+++ b/src/move.c
@@ -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);
 
diff --git a/src/testdir/test_cursor_func.vim b/src/testdir/test_cursor_func.vim
index 3cdf4cb7f..2bdda869e 100644
--- a/src/testdir/test_cursor_func.vim
+++ b/src/testdir/test_cursor_func.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 4bb1c90ba..15ff51dd7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2159,
 /**/
     2158,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rD5B3-00G9wO-Mo%40256bit.org.

Raspunde prin e-mail lui