diff options
| author | bors <bors@rust-lang.org> | 2017-04-07 15:25:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-04-07 15:25:47 +0000 |
| commit | 53f4bc311b5ff11a16185dd40dc116cf6b8cc162 (patch) | |
| tree | a53011ce53a42b7ce985f2cc53e76d8b56221de3 /src/libstd | |
| parent | c438c1fb39337b7712afc58df4f1f9c5112e5cc1 (diff) | |
| parent | cd2310b93cb8feb84435157455743aec39b86d80 (diff) | |
| download | rust-53f4bc311b5ff11a16185dd40dc116cf6b8cc162.tar.gz rust-53f4bc311b5ff11a16185dd40dc116cf6b8cc162.zip | |
Auto merge of #41138 - frewsxcv:rollup, r=frewsxcv
Rollup of 9 pull requests - Successful merges: #40797, #41047, #41056, #41061, #41075, #41080, #41120, #41130, #41131 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 2d14bb66bf4..fc1b9a97632 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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. |
