From 8793424b343155269011c05cba37b8a094edc120 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 2 Jan 2023 12:28:25 +0100 Subject: [PATCH] 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. --- vncviewer/fltk/theme.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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); } -- 2.39.5