@@ -60,6 +60,18 @@ use vec::Vec;
60
60
/// }
61
61
/// # }
62
62
/// ```
63
+ ///
64
+ /// # Safety
65
+ ///
66
+ /// `CString` is intended for working with traditional C-style strings
67
+ /// (a sequence of non-null bytes terminated by a single null byte); the
68
+ /// primary use case for these kinds of strings is interoperating with C-like
69
+ /// code. Often you will need to transfer ownership to/from that external
70
+ /// code. It is strongly recommended that you thoroughly read through the
71
+ /// documentation of `CString` before use, as improper ownership management
72
+ /// of `CString` instances can lead to invalid memory accesses, memory leaks,
73
+ /// and other memory errors.
74
+
63
75
#[ derive( PartialEq , PartialOrd , Eq , Ord , Hash , Clone ) ]
64
76
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
65
77
pub struct CString {
@@ -207,11 +219,11 @@ impl CString {
207
219
CString { inner : v. into_boxed_slice ( ) }
208
220
}
209
221
210
- /// Retakes ownership of a CString that was transferred to C.
222
+ /// Retakes ownership of a ` CString` that was transferred to C.
211
223
///
212
- /// The only appropriate argument is a pointer obtained by calling
213
- /// `into_raw`. The length of the string will be recalculated
214
- /// using the pointer.
224
+ /// This should only ever be called with a pointer that was earlier
225
+ /// obtained by calling `into_raw` on a `CString`. Additionally, the length
226
+ /// of the string will be recalculated from the pointer.
215
227
#[ stable( feature = "cstr_memory" , since = "1.4.0" ) ]
216
228
pub unsafe fn from_raw ( ptr : * mut c_char ) -> CString {
217
229
let len = libc:: strlen ( ptr) + 1 ; // Including the NUL byte
0 commit comments