]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0069: highlight: incorrect string length and redundant code v9.2.0069
authorglepnir <glephunter@gmail.com>
Fri, 27 Feb 2026 18:39:56 +0000 (18:39 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 27 Feb 2026 18:39:56 +0000 (18:39 +0000)
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 <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/highlight.c
src/version.c

index 2d524bcb378998bfb7854612c8c784e7b0390868..0c4fc056003e2c17c044f8bb8fdc8f8cffb9691a 100644 (file)
@@ -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);
index c93ea19fb0535e3494fa1db55cb0c9eaa03577e3..f2a793104ad43db4562e53e52641c4d465d99a28 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    69,
 /**/
     68,
 /**/