patch 9.1.0021: i_CTRL-R- doesn't work for multibyte chars in Replace mode

Commit: 
https://github.com/vim/vim/commit/424ec1f235a53131042aed94d30f6e2528e551d9
Author: zeertzjq <[email protected]>
Date:   Fri Jan 12 17:43:05 2024 +0100

    patch 9.1.0021: i_CTRL-R- doesn't work for multibyte chars in Replace mode
    
    Problem:  i_CTRL-R- doesn't work for multibyte chars in Replace mode,
              Coverity complains missing return value for u_save_cursor()
    Solution: Use mb_charlen() and del_chars() instead, handle failure mode
              for u_save_cursor() correctly (@zeertzjq)
    
    closes: #13846
    
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/register.c b/src/register.c
index f381e303b..8a4ae6748 100644
--- a/src/register.c
+++ b/src/register.c
@@ -832,8 +832,9 @@ insert_reg(
                    if ((State & REPLACE_FLAG) != 0)
                    {
                        pos_T curpos;
-                       u_save_cursor();
-                       del_bytes((long)STRLEN(y_current->y_array[0]), TRUE, 
FALSE);
+                       if (u_save_cursor() == FAIL)
+                           return FAIL;
+                       del_chars((long)mb_charlen(y_current->y_array[0]), 
TRUE);
                        curpos = curwin->w_cursor;
                        if (oneright() == FAIL)
                            // hit end of line, need to put forward (after the 
current position)
diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim
index 50f39107b..367d91498 100644
--- a/src/testdir/test_registers.vim
+++ b/src/testdir/test_registers.vim
@@ -949,7 +949,7 @@ endfunc
 func Test_insert_small_delete_replace_mode()
   new
   call setline(1, ['foo', 'bar', 'foobar',  'bar'])
-  let @-='foo'
+  let @- = 'foo'
   call cursor(2, 1)
   exe ":norm! R\<C-R>-\<C-R>-"
   call assert_equal('foofoo', getline(2))
@@ -960,9 +960,21 @@ func Test_insert_small_delete_replace_mode()
   exe ":norm! R\<C-R>-ZZZZ"
   call assert_equal(['foo', 'foofoo', '',  'bfoobarZZZZ'], getline(1, 4))
   call cursor(1, 1)
-  let @-=''
+  let @- = ''
   exe ":norm! R\<C-R>-ZZZ"
   call assert_equal(['ZZZ', 'foofoo', '',  'bfoobarZZZZ'], getline(1, 4))
+  let @- = 'βbβ'
+  call cursor(4, 1)
+  exe ":norm! R\<C-R>-"
+  call assert_equal(['ZZZ', 'foofoo', '',  'βbβobarZZZZ'], getline(1, 4))
+  let @- = 'bβb'
+  call cursor(4, 1)
+  exe ":norm! R\<C-R>-"
+  call assert_equal(['ZZZ', 'foofoo', '',  'bβbobarZZZZ'], getline(1, 4))
+  let @- = 'βbβ'
+  call cursor(4, 1)
+  exe ":norm! R\<C-R>-"
+  call assert_equal(['ZZZ', 'foofoo', '',  'βbβobarZZZZ'], getline(1, 4))
   bwipe!
 endfunc
 
diff --git a/src/version.c b/src/version.c
index 76a7668b0..b221faaae 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 */
+/**/
+    21,
 /**/
     20,
 /**/

-- 
-- 
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/E1rOKt1-008hsh-Cz%40256bit.org.

Raspunde prin e-mail lui