patch 9.1.2112: long statusline may crash if using singlebyte encoding

Commit: 
https://github.com/vim/vim/commit/3f7be0d7e1a394797c44090cdb9a231f1424187d
Author: zeertzjq <[email protected]>
Date:   Wed Jan 28 21:36:51 2026 +0000

    patch 9.1.2112: long statusline may crash if using singlebyte encoding
    
    Problem:  long statusline may crash if using singlebyte encoding
              (fizz-is-on-the-way)
    Solution: Drop the non-mbyte codepath and always use the mbyte code
              (zeertzjq)
    
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/buffer.c b/src/buffer.c
index 62f236ff0..86b784023 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5264,17 +5264,12 @@ build_stl_str_hl(
        {
            char_u  *end = out + outputlen;
 
-           if (has_mbyte)
+           n = 0;
+           while (width >= maxwidth)
            {
-               n = 0;
-               while (width >= maxwidth)
-               {
-                   width -= ptr2cells(s + n);
-                   n += (*mb_ptr2len)(s + n);
-               }
+               width -= ptr2cells(s + n);
+               n += (*mb_ptr2len)(s + n);
            }
-           else
-               n = width - maxwidth + 1;
            p = s + n;
            mch_memmove(s + 1, p, (size_t)(end - p) + 1);       // +1 for NUL
            end -= (size_t)(p - (s + 1));
diff --git a/src/testdir/test_statusline.vim b/src/testdir/test_statusline.vim
index 4899bd0a0..174c1a475 100644
--- a/src/testdir/test_statusline.vim
+++ b/src/testdir/test_statusline.vim
@@ -707,4 +707,18 @@ func Test_statusline_in_sandbox()
   delfunc Check_statusline_in_sandbox
 endfunc
 
+" This used to call memmove with a negative size and crash Vim
+func Test_statusline_singlebyte_negative()
+  let [_columns, _ls, _stl, _enc]  = [&columns, &ls, &stl, &enc]
+  set encoding=latin1
+  set laststatus=2 columns=15
+  setl stl=%#ErrorMsg#abcdtàØ ?}}o@`s`ÿæ Cú\x E%#Normal#
+  vsp
+  setl stl=%#ErrorMsg#abcdtàØ ?}}o@`s`ÿæ Cú\x E%#Normal#
+  redraw!
+  redrawstatus
+  bw!
+  let [&columns, &ls, &stl, &enc] = [_columns, _ls, _stl, _enc]
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index de16a77a4..f989c2ae4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2112,
 /**/
     2111,
 /**/

-- 
-- 
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 visit 
https://groups.google.com/d/msgid/vim_dev/E1vlDLT-0018FF-LO%40256bit.org.

Raspunde prin e-mail lui