diff options
Diffstat (limited to 'app/xterm/fontutils.c')
-rw-r--r-- | app/xterm/fontutils.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/app/xterm/fontutils.c b/app/xterm/fontutils.c index 14984e83a..1fb3df97a 100644 --- a/app/xterm/fontutils.c +++ b/app/xterm/fontutils.c @@ -1,4 +1,4 @@ -/* $XTermId: fontutils.c,v 1.383 2012/09/22 00:15:55 tom Exp $ */ +/* $XTermId: fontutils.c,v 1.386 2012/12/31 20:51:54 tom Exp $ */ /* * Copyright 1998-2011,2012 by Thomas E. Dickey @@ -89,8 +89,6 @@ } \ } -#define MAX_FONTNAME 200 - /* * A structure to hold the relevant properties from a font * we need to make a well formed font name for it. @@ -243,9 +241,6 @@ check_fontname(const char *name) if (IsEmpty(name)) { TRACE(("fontname missing\n")); result = False; - } else if (strlen(name) >= MAX_FONTNAME - 1) { - TRACE(("fontname too large: %s\n", name)); - result = False; } return result; } @@ -258,7 +253,7 @@ check_fontname(const char *name) * or NULL on error. */ static FontNameProperties * -get_font_name_props(Display * dpy, XFontStruct * fs, char *result) +get_font_name_props(Display * dpy, XFontStruct * fs, char **result) { static FontNameProperties props; static char *last_name; @@ -294,7 +289,9 @@ get_font_name_props(Display * dpy, XFontStruct * fs, char *result) if (result != 0) { if (!check_fontname(name)) return 0; - strcpy(result, name); + if (*result != 0) + free(*result); + *result = x_strdup(name); } /* @@ -515,7 +512,8 @@ xtermSpecialFont(TScreen * screen, unsigned atts, unsigned chrset) old_props.res_x = res_x; old_props.res_x = res_y; old_props.pixel_size = pixel_size; - old_props.spacing = strcpy(old_spacing, props->spacing); + old_props.spacing = old_spacing; + sprintf(old_spacing, "%.*s", (int) sizeof(old_spacing) - 2, props->spacing); } #endif @@ -584,13 +582,14 @@ same_font_name(const char *pattern, const char *match) static int got_bold_font(Display * dpy, XFontStruct * fs, String requested) { - char actual[MAX_FONTNAME]; + char *actual = 0; int got; - if (get_font_name_props(dpy, fs, actual) == 0) + if (get_font_name_props(dpy, fs, &actual) == 0) got = 0; else got = same_font_name(requested, actual); + free(actual); return got; } @@ -876,7 +875,7 @@ xtermLoadFont(XtermWidget xw, Pixel new_normal; Pixel new_revers; char *tmpname = NULL; - char normal[MAX_FONTNAME]; + char *normal = NULL; Boolean proportional = False; fontWarningTypes warn[fMAX]; int j; @@ -945,10 +944,10 @@ xtermLoadFont(XtermWidget xw, goto bad; } - strcpy(normal, myfonts.f_n); + normal = x_strdup(myfonts.f_n); if (!check_fontname(myfonts.f_b)) { warn[fBold] = fwAlways; - fp = get_font_name_props(screen->display, fnts[fNorm].fs, normal); + fp = get_font_name_props(screen->display, fnts[fNorm].fs, &normal); if (fp != 0) { myfonts.f_b = bold_font_name(fp, fp->average_width); if (!xtermOpenFont(xw, myfonts.f_b, &fnts[fBold], fwAlways, False)) { @@ -984,12 +983,12 @@ xtermLoadFont(XtermWidget xw, */ if_OPT_WIDE_CHARS(screen, { Boolean derived; - char bold[MAX_FONTNAME]; + char *bold = NULL; if (check_fontname(myfonts.f_w)) { cache_menu_font_name(screen, fontnum, fWide, myfonts.f_w); } else if (screen->utf8_fonts && !is_double_width_font(fnts[fNorm].fs)) { - fp = get_font_name_props(screen->display, fnts[fNorm].fs, normal); + fp = get_font_name_props(screen->display, fnts[fNorm].fs, &normal); if (fp != 0) { myfonts.f_w = wide_font_name(fp); warn[fWide] = fwAlways; @@ -1007,7 +1006,7 @@ xtermLoadFont(XtermWidget xw, derived = False; if (!check_fontname(myfonts.f_wb)) { - fp = get_font_name_props(screen->display, fnts[fBold].fs, bold); + fp = get_font_name_props(screen->display, fnts[fBold].fs, &bold); if (fp != 0) { myfonts.f_wb = widebold_font_name(fp); warn[fWBold] = fwAlways; @@ -1059,6 +1058,8 @@ xtermLoadFont(XtermWidget xw, TRACE(("...cannot load wide bold font, use wide %s\n", NonNull(myfonts.f_w))); } + free(bold); + if (EmptyFont(fnts[fWBold].fs)) goto bad; /* can't use a 0-sized font */ }); @@ -1251,12 +1252,16 @@ xtermLoadFont(XtermWidget xw, screen->menu_font_sizes[fontnum] = FontSize(fnts[fNorm].fs); #endif } + if (normal) + free(normal); set_cursor_gcs(xw); xtermUpdateFontInfo(xw, doresize); TRACE(("Success Cgs - xtermLoadFont\n")); return 1; bad: + if (normal) + free(normal); if (tmpname) free(tmpname); @@ -1537,9 +1542,9 @@ HandleLoadVTFonts(Widget w, char name_buf[80]; char class_buf[80]; String name = (String) ((*param_count > 0) ? params[0] : empty); - char *myName = (char *) MyStackAlloc(strlen(name), name_buf); + char *myName = (char *) MyStackAlloc(strlen(name) + 1, name_buf); String convert = (String) ((*param_count > 1) ? params[1] : myName); - char *myClass = (char *) MyStackAlloc(strlen(convert), class_buf); + char *myClass = (char *) MyStackAlloc(strlen(convert) + 1, class_buf); int n; TRACE(("HandleLoadVTFonts(%d)\n", *param_count)); |