changeset 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 f6a756c19bfb
children ec0a2b5493f8
files scripts/osx/deploy_build.sh src/core/anime.cc src/sys/osx/dark_theme.cc
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/osx/deploy_build.sh	Thu Apr 18 17:24:42 2024 -0400
+++ b/scripts/osx/deploy_build.sh	Thu Apr 18 19:23:31 2024 -0400
@@ -22,7 +22,7 @@
 	install_name_tool -change "/usr/local/lib/lib$i.0.dylib" "@executable_path/../Frameworks/lib$i.0.dylib" "$BUNDLE_NAME.app/Contents/MacOS/minori"
 done
 
-macdeployqt "$BUNDLE_NAME.app"
+macdeployqt "$BUNDLE_NAME.app" -no-strip
 if $FRAMEWORK_MODE; then
 	for i in QtCore QtGui QtWidgets; do
 		install_name_tool -id @executable_path/../Frameworks/$i.framework/Versions/5/$i $BUNDLE_NAME.app/Contents/Frameworks/$i.framework/Versions/5/$i
--- a/src/core/anime.cc	Thu Apr 18 17:24:42 2024 -0400
+++ b/src/core/anime.cc	Thu Apr 18 19:23:31 2024 -0400
@@ -10,6 +10,7 @@
 #include <algorithm>
 #include <string>
 #include <vector>
+#include <cassert>
 
 namespace Anime {
 
--- 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);