diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-06-03 23:32:26 +0200 |
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-06-03 23:32:26 +0200 |
| commit | 00a7b56bab317d9f1aaa5255145ce3414081cbfe (patch) | |
| tree | 53645e9510aae24e74803e662b0013edc6932659 | |
| parent | eeaf497b2a6bc065874e3d3367b1f3023c5bb3d3 (diff) | |
| download | rust-00a7b56bab317d9f1aaa5255145ce3414081cbfe.tar.gz rust-00a7b56bab317d9f1aaa5255145ce3414081cbfe.zip | |
Added the documentation about length to CString::from_raw
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 4bac9a4917d..3d7ac724fbd 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -395,6 +395,12 @@ impl CString { /// ownership of a string that was allocated by foreign code) is likely to lead /// to undefined behavior or allocator corruption. /// + /// It should be noted that the length isn't just "recomputed," but that + /// the recomputed length must match the original length from the + /// [`into_raw`] call. This means the [`into_raw`]/`from_raw` methods + /// should not be used when passing the string to C functions that can + /// modify the string's length. + /// /// > **Note:** If you need to borrow a string that was allocated by /// > foreign code, use [`CStr`]. If you need to take ownership of /// > a string that was allocated by foreign code, you will need to |
