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 locale1.2.x
parent
36f647e875
commit
8d2d557da9
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue