Skip to content

Commit 727837f

Browse files
committed
Use MaybeUninit instead of mem::uninitialized
1 parent 80a9bf0 commit 727837f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

core-foundation/src/filedescriptor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags};
1515
use base::TCFType;
1616
use runloop::CFRunLoopSource;
1717

18-
use std::mem;
18+
use std::mem::MaybeUninit;
1919
use std::os::unix::io::{AsRawFd, RawFd};
2020
use std::ptr;
2121

@@ -46,9 +46,9 @@ impl CFFileDescriptor {
4646

4747
pub fn context(&self) -> CFFileDescriptorContext {
4848
unsafe {
49-
let mut context: CFFileDescriptorContext = mem::uninitialized();
50-
CFFileDescriptorGetContext(self.0, &mut context);
51-
context
49+
let mut context = MaybeUninit::<CFFileDescriptorContext>::uninit();
50+
CFFileDescriptorGetContext(self.0, context.as_mut_ptr());
51+
context.assume_init()
5252
}
5353
}
5454

core-foundation/src/url.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use string::{CFString};
1616

1717
use core_foundation_sys::base::{kCFAllocatorDefault, Boolean};
1818
use std::fmt;
19+
use std::mem::MaybeUninit;
1920
use std::ptr;
2021
use std::path::{Path, PathBuf};
21-
use std::mem;
2222

2323
use libc::{c_char, strlen, PATH_MAX};
2424

@@ -78,13 +78,15 @@ 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: [u8; PATH_MAX as usize] = mem::uninitialized();
82-
let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr(), buf.len() as CFIndex);
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);
8383
if result == false as Boolean {
8484
return None;
8585
}
86-
let len = strlen(buf.as_ptr() as *const c_char);
87-
let path = OsStr::from_bytes(&buf[0..len]);
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]);
8890
Some(PathBuf::from(path))
8991
}
9092
}

0 commit comments

Comments
 (0)