rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.69k stars 12.64k forks source link

Document the requirement on recomputed length for CString::from_raw #48525

Closed ExpHP closed 4 years ago

ExpHP commented 6 years ago

A recent Doc PR for CStr reminded me of this:

https://users.rust-lang.org/t/cstring-from-raw-danger/15340

frewsxcv commented 6 years ago

We might want to reuse some of the language from Vec::from_raw_parts:

  • ptr needs to have been previously allocated via String/Vec<T> (at least, it's highly likely to be incorrect if it wasn't).
    • ptr's T needs to have the same size and alignment as it was allocated with.