[macOS] Add null checks for `NSString stringWithUTF8String`.

This commit is contained in:
bruvzg 2024-02-23 08:20:02 +02:00
parent f15ced3f18
commit d2e0544e0a
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
2 changed files with 6 additions and 4 deletions

View File

@ -41,9 +41,10 @@
String DirAccessMacOS::fix_unicode_name(const char *p_name) const {
String fname;
NSString *nsstr = [[NSString stringWithUTF8String:p_name] precomposedStringWithCanonicalMapping];
fname.parse_utf8([nsstr UTF8String]);
if (p_name != nullptr) {
NSString *nsstr = [[NSString stringWithUTF8String:p_name] precomposedStringWithCanonicalMapping];
fname.parse_utf8([nsstr UTF8String]);
}
return fname;
}

View File

@ -125,7 +125,8 @@
- (void)applicationDidFinishLaunching:(NSNotification *)notice {
NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *nsbundleid_env = [NSString stringWithUTF8String:getenv("__CFBundleIdentifier")];
const char *bundled_id = getenv("__CFBundleIdentifier");
NSString *nsbundleid_env = [NSString stringWithUTF8String:(bundled_id != nullptr) ? bundled_id : ""];
NSString *nsbundleid = [[NSBundle mainBundle] bundleIdentifier];
if (nsappname == nil || isatty(STDOUT_FILENO) || isatty(STDIN_FILENO) || isatty(STDERR_FILENO) || ![nsbundleid isEqualToString:nsbundleid_env]) {
// If the executable is started from terminal or is not bundled, macOS WindowServer won't register and activate app window correctly (menu and title bar are grayed out and input ignored).