From ec40e2d85c085677138a69ee63d82067f4dda67e Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 3 Apr 2025 18:47:13 -0400 Subject: [PATCH] gpui: Avoid dereferencing null pointer in `MacWindow::active_window` (#28059) This PR adds a check to avoid dereferencing a null pointer in `MacWindow::active_window`. Rust 1.86 now has a [debug assertion for dereferencing null pointers](https://blog.rust-lang.org/2025/04/03/Rust-1.86.0.html#debug-assertions-that-pointers-are-non-null-when-required-for-soundness), which means that losing focus of the window would cause a null pointer to be dereferenced and panic. Release Notes: - N/A --- crates/gpui/src/platform/mac/window.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index e655e067f8..936b6df48a 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -744,6 +744,10 @@ impl MacWindow { unsafe { let app = NSApplication::sharedApplication(nil); let main_window: id = msg_send![app, mainWindow]; + if main_window.is_null() { + return None; + } + if msg_send![main_window, isKindOfClass: WINDOW_CLASS] { let handle = get_window_state(&*main_window).lock().handle; Some(handle)