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
pull/9301/head
Jared Gizersky 2025-10-20 23:27:04 -04:00 committed by GitHub
parent da165fc3cf
commit 3548acfac6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -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");