Skip to content

Commit 00a7b56

Browse files
committed
Added the documentation about length to CString::from_raw
1 parent eeaf497 commit 00a7b56

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ impl CString {
395395
/// ownership of a string that was allocated by foreign code) is likely to lead
396396
/// to undefined behavior or allocator corruption.
397397
///
398+
/// It should be noted that the length isn't just "recomputed," but that
399+
/// the recomputed length must match the original length from the
400+
/// [`into_raw`] call. This means the [`into_raw`]/`from_raw` methods
401+
/// should not be used when passing the string to C functions that can
402+
/// modify the string's length.
403+
///
398404
/// > **Note:** If you need to borrow a string that was allocated by
399405
/// > foreign code, use [`CStr`]. If you need to take ownership of
400406
/// > a string that was allocated by foreign code, you will need to

0 commit comments

Comments
 (0)