Closed
Description
Consider the following code:
use std::ffi::CString;
fn main() {
let c = CString::new(&b"Hello, world"[..]).unwrap();
let ptr = c.into_raw();
unsafe {
*ptr = 0;
CString::from_raw(ptr); // UB
}
}
Shortening the string from CString::into_raw
and then passing it to CString::from_raw
will cause UB, but this is not documented in safety section of the documentation.