# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1611522015 0 # Node ID 15347d28995a04723742f73a9ff73f3f46e5d4d5 # Parent a691de150befeb625f94fdf146403953aeca6e4f OS/2: Fix crash in dw_window_set_font() with NULL fontname. diff -r a691de150bef -r 15347d28995a os2/dw.c --- a/os2/dw.c Sun Jan 24 20:20:06 2021 +0000 +++ b/os2/dw.c Sun Jan 24 21:00:15 2021 +0000 @@ -5056,8 +5056,9 @@ { char *oldfont = DefaultFont; - DefaultFont = strdup(fontname); - free(oldfont); + DefaultFont = fontname ? strdup(fontname) : NULL; + if(oldfont) + free(oldfont); } /* Internal function to return a pointer to an item struct @@ -5492,8 +5493,11 @@ int API dw_window_set_font(HWND handle, const char *fontname) { HWND group = (HWND)dw_window_get_data(handle, "_dw_buddy"); + const char *font = fontname ? fontname : DefaultFont; + /* If we changed the font... */ - if(!WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(fontname)+1, (void *)fontname)) + if((!font && WinRemovePresParam(group ? group : handle, PP_FONTNAMESIZE)) || + (font && WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(font)+1, (void *)font))) { Item *item = _box_item(handle);