{mac,cocoa}: trim trailing null out of macosx_icon when loading it

This prevents crashes when loading the application icon image.

Suggested-by: Akemi <der.richter@gmx.de>
This commit is contained in:
Rodger Combs 2018-07-01 04:56:08 -05:00 committed by Jan Ekström
parent ada4f7c600
commit 1842a932d3
2 changed files with 5 additions and 2 deletions

View File

@ -127,8 +127,9 @@ static const char macosx_icon[] =
- (NSImage *)getMPVIcon
{
// The C string contains a trailing null, so we strip it away
NSData *icon_data = [NSData dataWithBytesNoCopy:(void *)macosx_icon
length:sizeof(macosx_icon)
length:sizeof(macosx_icon) - 1
freeWhenDone:NO];
return [[NSImage alloc] initWithData:icon_data];
}

View File

@ -172,8 +172,10 @@ static void set_application_icon(NSApplication *app)
NSBundle *bundle = [NSBundle mainBundle];
if ([bundle pathForResource:@"icon" ofType:@"icns"])
return;
// The C string contains a trailing null, so we strip it away
NSData *icon_data = [NSData dataWithBytesNoCopy:(void *)macosx_icon
length:sizeof(macosx_icon)
length:sizeof(macosx_icon) - 1
freeWhenDone:NO];
NSImage *icon = [[NSImage alloc] initWithData:icon_data];
[app setApplicationIconImage:icon];