]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0021: i_CTRL-R- doesn't work for multibyte chars in Replace mode v9.1.0021
authorzeertzjq <zeertzjq@outlook.com>
Fri, 12 Jan 2024 16:43:05 +0000 (17:43 +0100)
committerChristian Brabandt <cb@256bit.org>
Fri, 12 Jan 2024 16:43:05 +0000 (17:43 +0100)
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 <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/register.c
src/testdir/test_registers.vim
src/version.c

index f381e303beb7eb2f95592986b8a5d5df8696f00d..8a4ae674897659b64517924f9af49512d78c21f4 100644 (file)
@@ -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)
index 50f39107b469a4e5c4c26267b68b52ec89c5d4a2..367d9149872e9f6c0fbdeebf1c54a22fdabf13f8 100644 (file)
@@ -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
 
index 76a7668b0e7b9c13c3d097254bd458af60a5a742..b221faaae09cab40c6af4c36de3adc78c76d8a8e 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    21,
 /**/
     20,
 /**/