From 3548acfac63e7674b5e25896f6b393474fe8ea65 Mon Sep 17 00:00:00 2001 From: Jared Gizersky <77700596+jaredgizersky@users.noreply.github.com> Date: Mon, 20 Oct 2025 23:27:04 -0400 Subject: [PATCH] os: handle nil languageCode/countryCode in setLangFromCocoa (#9290) Fixes a crash when NSLocale returns nil for languageCode or countryCode properties. This can happen when the app launches without locale environment variables set. The crash occurs at `src/os/locale.zig:87-88` when trying to call `getProperty()` on a nil object. The fix adds a null check and falls back to `en_US.UTF-8` instead of dereferencing null. ## Testing Tested by running with locale variables unset: ```bash unset LC_ALL && ./zig-out/Ghostty.app/Contents/MacOS/ghostty ``` Before: segmentation fault After: launches successfully with fallback locale --- src/os/locale.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/os/locale.zig b/src/os/locale.zig index b391d690f..92a63741f 100644 --- a/src/os/locale.zig +++ b/src/os/locale.zig @@ -83,6 +83,11 @@ fn setLangFromCocoa() void { const lang = locale.getProperty(objc.Object, "languageCode"); const country = locale.getProperty(objc.Object, "countryCode"); + if (lang.value == null or country.value == null) { + log.warn("languageCode or countryCode not found. Locale may be incorrect.", .{}); + return; + } + // Get our UTF8 string values const c_lang = lang.getProperty([*:0]const u8, "UTF8String"); const c_country = country.getProperty([*:0]const u8, "UTF8String");