Skip to content

Commit 9ffb545

Browse files
author
Clar Charr
committed
Remove some CStr transmutes.
1 parent 44855a4 commit 9ffb545

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/libstd/ffi/c_str.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl ops::Deref for CString {
356356
type Target = CStr;
357357

358358
fn deref(&self) -> &CStr {
359-
unsafe { mem::transmute(self.as_bytes_with_nul()) }
359+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
360360
}
361361
}
362362

@@ -583,7 +583,8 @@ impl CStr {
583583
#[stable(feature = "rust1", since = "1.0.0")]
584584
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
585585
let len = libc::strlen(ptr);
586-
mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
586+
let ptr = ptr as *const u8;
587+
CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1))
587588
}
588589

589590
/// Creates a C string wrapper from a byte slice.

0 commit comments

Comments
 (0)