about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLemonJ <1632798336@qq.com>2025-02-27 15:18:10 +0800
committerLemonJ <1632798336@qq.com>2025-04-27 12:49:37 +0800
commitbfdd947bbd5a2d242d0cbd728b3cbf2a30206b74 (patch)
tree1adcffbdfed7f5cdea167b9613e8950625a4ed74
parent00f245915b0c7839d42c26f9628220c4f1b93bf6 (diff)
downloadrust-bfdd947bbd5a2d242d0cbd728b3cbf2a30206b74.tar.gz
rust-bfdd947bbd5a2d242d0cbd728b3cbf2a30206b74.zip
fix missing doc in CString::from_raw and str::from_boxed_utf8_unchecked
-rw-r--r--library/alloc/src/ffi/c_str.rs11
-rw-r--r--library/alloc/src/str.rs4
2 files changed, 12 insertions, 3 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs
index fd93045a5ac..5bd5d3ec2c8 100644
--- a/library/alloc/src/ffi/c_str.rs
+++ b/library/alloc/src/ffi/c_str.rs
@@ -352,9 +352,14 @@ impl CString {
     /// # Safety
     ///
     /// This should only ever be called with a pointer that was earlier
-    /// obtained by calling [`CString::into_raw`]. Other usage (e.g., trying to take
-    /// ownership of a string that was allocated by foreign code) is likely to lead
-    /// to undefined behavior or allocator corruption.
+    /// obtained by calling [`CString::into_raw`], and the memory it points to must not be accessed
+    /// through any other pointer during the lifetime of reconstructed `CString`.
+    /// Other usage (e.g., trying to take ownership of a string that was allocated by foreign code)
+    /// is likely to lead to undefined behavior or allocator corruption.
+    ///
+    /// This function does not validate ownership of the raw pointer's memory.
+    /// A double-free may occur if the function is called twice on the same raw pointer.
+    /// Additionally, the caller must ensure the pointer is not dangling.
     ///
     /// It should be noted that the length isn't just "recomputed," but that
     /// the recomputed length must match the original length from the
diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs
index 6fee8d3fe33..a670bb5008a 100644
--- a/library/alloc/src/str.rs
+++ b/library/alloc/src/str.rs
@@ -604,6 +604,10 @@ impl str {
 /// Converts a boxed slice of bytes to a boxed string slice without checking
 /// that the string contains valid UTF-8.
 ///
+/// # Safety
+///
+/// * The provided bytes must contain a valid UTF-8 sequence.
+///
 /// # Examples
 ///
 /// ```