Mercurial > minori
diff src/sys/osx/dark_theme.cc @ 275:22f9aacf6ac1
osx: don't dereference NULL pointers
fail
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 18 Apr 2024 19:23:31 -0400 |
parents | f31305b9f60a |
children |
line wrap: on
line diff
--- a/src/sys/osx/dark_theme.cc Thu Apr 18 17:24:42 2024 -0400 +++ b/src/sys/osx/dark_theme.cc Thu Apr 18 19:23:31 2024 -0400 @@ -22,22 +22,27 @@ CFBundleRef appkit_bundle = CFBundleGetBundleWithIdentifier(kAppKitBundleID); if (!appkit_bundle) return false; - - NSAppearanceNameAqua = - *reinterpret_cast<CFStringRef*>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); - if (!NSAppearanceNameAqua) + + auto aqua_appearance = reinterpret_cast<CFStringRef*>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); + if (!aqua_appearance) return false; + NSAppearanceNameAqua = *aqua_appearance; - NSAppearanceNameDarkAqua = *reinterpret_cast<CFStringRef*>( + auto dark_aqua_appearance = reinterpret_cast<CFStringRef*>( CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameDarkAqua"))); - if (!NSAppearanceNameDarkAqua) + if (!dark_aqua_appearance) return false; + NSAppearanceNameDarkAqua = *dark_aqua_appearance; return true; } bool DarkThemeAvailable() { - return (__builtin_available(macOS 10.14, *)); + if (__builtin_available(macOS 10.14, *)) { + return true; + } else { + return false; + } } bool IsInDarkTheme() { @@ -56,6 +61,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* effectiveAppearance = [app effectiveAppearance]; const id effectiveAppearance = obj_send(app, sel_getUid("effectiveAppearance")); @@ -86,6 +93,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua]; const id appearance = @@ -109,6 +118,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua]; const id appearance = cls_send(objc_getClass("NSAppearance"), sel_getUid("appearanceNamed:"), NSAppearanceNameAqua); @@ -126,6 +137,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return; // [app setAppearance: null]; obj_send(app, sel_getUid("setAppearance:"), nullptr);