diff --git a/src/tz_macos.rs b/src/tz_macos.rs index 165c539..4d20909 100644 --- a/src/tz_macos.rs +++ b/src/tz_macos.rs @@ -11,19 +11,22 @@ unsafe fn get_timezone() -> Option { // The longest name in the IANA time zone database is 25 ASCII characters long. const MAX_LEN: usize = 32; - // Get system time zone, and its name. + // Get system time zone, and borrow its name. let tz = Dropping::new(CFTimeZoneCopySystem())?; - let name = Dropping::new(CFTimeZoneGetName(tz.0))?; + let name = match CFTimeZoneGetName(tz.0) { + name if !name.is_null() => name, + _ => return None, + }; // Copy the name into the buffer. let mut buf = [0; MAX_LEN]; let mut buf_bytes = 0; let range = CFRange { location: 0, - length: CFStringGetLength(name.0), + length: CFStringGetLength(name), }; if CFStringGetBytes( - name.0, + name, range, kCFStringEncodingUTF8, b'\0',