patch 9.2.0069: highlight: incorrect string length and redundant code

Commit: 
https://github.com/vim/vim/commit/09ce70821b923dd4ce10765135f56c3a410a5504
Author: glepnir <[email protected]>
Date:   Fri Feb 27 18:39:56 2026 +0000

    patch 9.2.0069: highlight: incorrect string length and redundant code
    
    Problem:  The length passed to add_attr_and_value for " ctermfont=" is
              incorrect. In highlight_set_font(), sg_font_name is freed and
              updated in two separate branches, leading to redundant code.
    Solution: Correct the length parameter in hlg_add_or_update().
              Refactor highlight_set_font() to update the font name string
              only once after a successful change is detected.
    
    closes: #19512
    
    Signed-off-by: glepnir <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/highlight.c b/src/highlight.c
index 2d524bcb3..0c4fc0560 100644
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -995,8 +995,6 @@ highlight_set_font(
            // New fontset was accepted. Free the old one, if there
            // was one.
            gui_mch_free_fontset(temp_sg_fontset);
-           vim_free(HL_TABLE()[idx].sg_font_name);
-           HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
            did_change = TRUE;
        }
        else
@@ -1007,12 +1005,17 @@ highlight_set_font(
            // New font was accepted. Free the old one, if there was
            // one.
            gui_mch_free_font(temp_sg_font);
-           vim_free(HL_TABLE()[idx].sg_font_name);
-           HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
            did_change = TRUE;
        }
        else
            HL_TABLE()[idx].sg_font = temp_sg_font;
+       // Update sg_font_name once here, after both font and fontset results
+       // are known.
+       if (did_change)
+       {
+           vim_free(HL_TABLE()[idx].sg_font_name);
+           HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
+       }
     }
 
     return did_change;
@@ -5347,7 +5350,7 @@ hlg_add_or_update(dict_T *dict)
     p = add_attr_and_value(p, (char_u *)" ctermfg=", 9, ctermfg);
     p = add_attr_and_value(p, (char_u *)" ctermbg=", 9, ctermbg);
     p = add_attr_and_value(p, (char_u *)" ctermul=", 9, ctermul);
-    p = add_attr_and_value(p, (char_u *)" ctermfont=", 9, ctermfont);
+    p = add_attr_and_value(p, (char_u *)" ctermfont=", 11, ctermfont);
     p = add_attr_and_value(p, (char_u *)" gui=", 5, gui_attr);
 # ifdef FEAT_GUI
     p = add_attr_and_value(p, (char_u *)" font=", 6, font);
diff --git a/src/version.c b/src/version.c
index c93ea19fb..f2a793104 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 */
+/**/
+    69,
 /**/
     68,
 /**/

-- 
-- 
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/E1vw34H-00G5du-7y%40256bit.org.

Raspunde prin e-mail lui