From: Pierre Ossman Date: Mon, 2 Jan 2023 11:28:25 +0000 (+0100) Subject: Keep font name in permanent memory X-Git-Tag: v1.13.90~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8793424b343155269011c05cba37b8a094edc120;p=tigervnc.git Keep font name in permanent memory Fl::set_font() doesn't keep its own copy, so we need to make sure the font string doesn't get freed or overwritten at a later point. --- diff --git a/vncviewer/fltk/theme.cxx b/vncviewer/fltk/theme.cxx index cb786e4c..d6748091 100644 --- a/vncviewer/fltk/theme.cxx +++ b/vncviewer/fltk/theme.cxx @@ -41,6 +41,10 @@ void init_theme() { +#if defined(WIN32) || defined(__APPLE__) + static char font_name[256]; +#endif + // Basic text size (10pt @ 96 dpi => 13px) FL_NORMAL_SIZE = 13; @@ -62,21 +66,22 @@ void init_theme() NONCLIENTMETRICS metrics; metrics.cbSize = sizeof(metrics); if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, - sizeof(metrics), &metrics, 0)) - Fl::set_font(FL_HELVETICA, metrics.lfMessageFont.lfFaceName); + sizeof(metrics), &metrics, 0)) { + strcpy(font_name, metrics.lfMessageFont.lfFaceName); + Fl::set_font(FL_HELVETICA, font_name); + } #elif defined(__APPLE__) CTFontRef font; CFStringRef name; - char cname[256]; font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0.0, NULL); if (font != NULL) { name = CTFontCopyFullName(font); if (name != NULL) { - CFStringGetCString(name, cname, sizeof(cname), + CFStringGetCString(name, font_name, sizeof(font_name), kCFStringEncodingUTF8); - Fl::set_font(FL_HELVETICA, cname); + Fl::set_font(FL_HELVETICA, strdup(font_name)); CFRelease(name); }