We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 44855a4 commit 9ffb545Copy full SHA for 9ffb545
src/libstd/ffi/c_str.rs
@@ -356,7 +356,7 @@ impl ops::Deref for CString {
356
type Target = CStr;
357
358
fn deref(&self) -> &CStr {
359
- unsafe { mem::transmute(self.as_bytes_with_nul()) }
+ unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
360
}
361
362
@@ -583,7 +583,8 @@ impl CStr {
583
#[stable(feature = "rust1", since = "1.0.0")]
584
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
585
let len = libc::strlen(ptr);
586
- mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
+ let ptr = ptr as *const u8;
587
+ CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1))
588
589
590
/// Creates a C string wrapper from a byte slice.
0 commit comments