Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d3acd47

Browse files
DiuDiu777tgross35
andcommittedApr 27, 2025·
fix missing doc in CString::from_raw and str::from_boxed_utf8_unchecked
Co-authored-by: Trevor Gross <[email protected]>
1 parent 00f2459 commit d3acd47

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎library/alloc/src/ffi/c_str.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,14 @@ impl CString {
352352
/// # Safety
353353
///
354354
/// This should only ever be called with a pointer that was earlier
355-
/// obtained by calling [`CString::into_raw`]. Other usage (e.g., trying to take
356-
/// ownership of a string that was allocated by foreign code) is likely to lead
357-
/// to undefined behavior or allocator corruption.
355+
/// obtained by calling [`CString::into_raw`], and the memory it points to must not be accessed
356+
/// through any other pointer during the lifetime of reconstructed `CString`.
357+
/// Other usage (e.g., trying to take ownership of a string that was allocated by foreign code)
358+
/// is likely to lead to undefined behavior or allocator corruption.
359+
///
360+
/// This function does not validate ownership of the raw pointer's memory.
361+
/// A double-free may occur if the function is called twice on the same raw pointer.
362+
/// Additionally, the caller must ensure the pointer is not dangling.
358363
///
359364
/// It should be noted that the length isn't just "recomputed," but that
360365
/// the recomputed length must match the original length from the

‎library/alloc/src/str.rs

+4
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ impl str {
604604
/// Converts a boxed slice of bytes to a boxed string slice without checking
605605
/// that the string contains valid UTF-8.
606606
///
607+
/// # Safety
608+
///
609+
/// * The provided bytes must contain a valid UTF-8 sequence.
610+
///
607611
/// # Examples
608612
///
609613
/// ```

0 commit comments

Comments
 (0)
Please sign in to comment.