-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.