Mercurial > dwindows
comparison os2/dw.c @ 2251:15347d28995a
OS/2: Fix crash in dw_window_set_font() with NULL fontname.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 24 Jan 2021 21:00:15 +0000 |
parents | a0c386cd332b |
children | 3361ce6070ce |
comparison
equal
deleted
inserted
replaced
2250:a691de150bef | 2251:15347d28995a |
---|---|
5054 */ | 5054 */ |
5055 void API dw_font_set_default(const char *fontname) | 5055 void API dw_font_set_default(const char *fontname) |
5056 { | 5056 { |
5057 char *oldfont = DefaultFont; | 5057 char *oldfont = DefaultFont; |
5058 | 5058 |
5059 DefaultFont = strdup(fontname); | 5059 DefaultFont = fontname ? strdup(fontname) : NULL; |
5060 free(oldfont); | 5060 if(oldfont) |
5061 free(oldfont); | |
5061 } | 5062 } |
5062 | 5063 |
5063 /* Internal function to return a pointer to an item struct | 5064 /* Internal function to return a pointer to an item struct |
5064 * with information about the packing information regarding object. | 5065 * with information about the packing information regarding object. |
5065 */ | 5066 */ |
5490 * fontname: Name and size of the font in the form "size.fontname" | 5491 * fontname: Name and size of the font in the form "size.fontname" |
5491 */ | 5492 */ |
5492 int API dw_window_set_font(HWND handle, const char *fontname) | 5493 int API dw_window_set_font(HWND handle, const char *fontname) |
5493 { | 5494 { |
5494 HWND group = (HWND)dw_window_get_data(handle, "_dw_buddy"); | 5495 HWND group = (HWND)dw_window_get_data(handle, "_dw_buddy"); |
5496 const char *font = fontname ? fontname : DefaultFont; | |
5497 | |
5495 /* If we changed the font... */ | 5498 /* If we changed the font... */ |
5496 if(!WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(fontname)+1, (void *)fontname)) | 5499 if((!font && WinRemovePresParam(group ? group : handle, PP_FONTNAMESIZE)) || |
5500 (font && WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(font)+1, (void *)font))) | |
5497 { | 5501 { |
5498 Item *item = _box_item(handle); | 5502 Item *item = _box_item(handle); |
5499 | 5503 |
5500 /* Check to see if any of the sizes need to be recalculated */ | 5504 /* Check to see if any of the sizes need to be recalculated */ |
5501 if(item && (item->origwidth == -1 || item->origheight == -1)) | 5505 if(item && (item->origwidth == -1 || item->origheight == -1)) |