]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/ffi/c_str.rs
cstring: avoid excessive growth just to 0-terminate
[rust.git] / src / libstd / ffi / c_str.rs
index 77b90c0846bbe44f2349b7a674223d6f47ea59f9..6f217be31fe678e513fbf5a3ac95a9b5d1b1cd1a 100644 (file)
@@ -213,6 +213,7 @@ fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
     /// byte vector, not anything that can be converted to one with Into.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
+        v.reserve_exact(1);
         v.push(0);
         CString { inner: v.into_boxed_slice() }
     }