Skip to content

Commit 83b6f5d

Browse files
committed
Use zero-initialized array in CFURL::to_path
1 parent d3a097f commit 83b6f5d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

core-foundation/src/url.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ impl CFURL {
7878
pub fn to_path(&self) -> Option<PathBuf> {
7979
// implementing this on Windows is more complicated because of the different OsStr representation
8080
unsafe {
81-
let mut buf = MaybeUninit::<[u8; PATH_MAX as usize]>::uninit();
82-
let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr() as *mut u8, PATH_MAX as CFIndex);
81+
let mut buf = [0u8; PATH_MAX as usize];
82+
let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr(), buf.len() as CFIndex);
8383
if result == false as Boolean {
8484
return None;
8585
}
86-
87-
let buf_init = buf.assume_init();
88-
let len = strlen(buf_init.as_ptr() as *const c_char);
89-
let path = OsStr::from_bytes(&buf_init[0..len]);
86+
let len = strlen(buf.as_ptr() as *const c_char);
87+
let path = OsStr::from_bytes(&buf[0..len]);
9088
Some(PathBuf::from(path))
9189
}
9290
}

0 commit comments

Comments
 (0)