Skip to content

Commit cdc4c8d

Browse files
committed
fix missing doc in two APIs
1 parent 00f2459 commit cdc4c8d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

library/alloc/src/ffi/c_str.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,13 @@ 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 this pointer 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.
358362
///
359363
/// It should be noted that the length isn't just "recomputed," but that
360364
/// the recomputed length must match the original length from the

library/alloc/src/str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ 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+
///
611+
/// * The `Box<[u8]>` must have been allocated via the global allocator.
612+
///
607613
/// # Examples
608614
///
609615
/// ```

0 commit comments

Comments
 (0)