patch 9.2.0069: highlight: incorrect string length and redundant code
Commit:
https://github.com/vim/vim/commit/09ce70821b923dd4ce10765135f56c3a410a5504
Author: glepnir <
gleph...@gmail.com>
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 <
gleph...@gmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
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,
/**/