]> git.lizzy.rs Git - rust.git/commitdiff
Remove some CStr transmutes.
authorClar Charr <clar@charr.xyz>
Thu, 6 Apr 2017 18:43:37 +0000 (14:43 -0400)
committerClar Charr <clar@charr.xyz>
Thu, 6 Apr 2017 21:42:02 +0000 (17:42 -0400)
src/libstd/ffi/c_str.rs

index 2d14bb66bf4f976e6016832f1ff17050d008fe9c..fc1b9a976322ea50e4580380368cd437a39bcc08 100644 (file)
@@ -356,7 +356,7 @@ impl ops::Deref for CString {
     type Target = CStr;
 
     fn deref(&self) -> &CStr {
-        unsafe { mem::transmute(self.as_bytes_with_nul()) }
+        unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
     }
 }
 
@@ -583,7 +583,8 @@ impl CStr {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
         let len = libc::strlen(ptr);
-        mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
+        let ptr = ptr as *const u8;
+        CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1))
     }
 
     /// Creates a C string wrapper from a byte slice.