diff options
author | marc_culler <marc.culler@gmail.com> | 2022-09-21 17:59:22 (GMT) |
---|---|---|
committer | marc_culler <marc.culler@gmail.com> | 2022-09-21 17:59:22 (GMT) |
commit | 0c682e76e15f569391daddd41dc963dee8829a60 (patch) | |
tree | 1ccf0f1e69cee678093fedc2c8236c38e362e804 | |
parent | fbda9c87baf1a96bb9cc195d99f465d3f3f2f3d6 (diff) | |
download | tk-0c682e76e15f569391daddd41dc963dee8829a60.zip tk-0c682e76e15f569391daddd41dc963dee8829a60.tar.gz tk-0c682e76e15f569391daddd41dc963dee8829a60.tar.bz2 |
tkMacOSXFileTypes.c: Guard against crashes when a nil UTType is created.
-rw-r--r-- | macosx/tkMacOSXFileTypes.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/macosx/tkMacOSXFileTypes.c b/macosx/tkMacOSXFileTypes.c index c89328d..c5beb67 100644 --- a/macosx/tkMacOSXFileTypes.c +++ b/macosx/tkMacOSXFileTypes.c @@ -77,15 +77,17 @@ MODULE_SCOPE NSImage *TkMacOSXIconForFileType(NSString *filetype) { } if (@available(macOS 11.0, *)) { UTType *uttype = [UTType typeWithIdentifier: filetype]; - if (![uttype isDeclared]) { + if (uttype == nil || !uttype.isDeclared) { uttype = [UTType typeWithFilenameExtension: filetype]; } - if (![uttype isDeclared] && [filetype length] == 4) { + if (uttype == nil || (!uttype.isDeclared && filetype.length == 4)) { OSType ostype = CHARS_TO_OSTYPE(filetype.UTF8String); NSString *UTI = TkMacOSXOSTypeToUTI(ostype); - uttype = [UTType typeWithIdentifier:UTI]; + if (UTI) { + uttype = [UTType typeWithIdentifier:UTI]; + } } - if (![uttype isDeclared]) { + if (uttype == nil || !uttype.isDeclared) { return nil; } return [[NSWorkspace sharedWorkspace] iconForContentType:uttype]; |