Skip to content

Commit

Permalink
Merge pull request #88694 from bruvzg/str_checks
Browse files Browse the repository at this point in the history
[macOS] Add null checks for `NSString stringWithUTF8String`.
  • Loading branch information
akien-mga committed Feb 25, 2024
2 parents e69cdf3 + d2e0544 commit a030031
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions platform/macos/dir_access_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion platform/macos/godot_application_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ - (void)system_theme_changed:(NSNotification *)notification {

- (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).
Expand Down

0 comments on commit a030031

Please sign in to comment.