From 0d3d23bdeed507e20a565ef89c3e2c4d51348022 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Fri, 26 Aug 2016 13:17:45 -0400 Subject: add stronger warning to CString::from_raw --- src/libstd/ffi/c_str.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 2d5e8c04194..d8785142795 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -228,9 +228,14 @@ impl CString { /// Retakes ownership of a `CString` that was transferred to C. /// + /// Additionally, the length of the string will be recalculated from the pointer. + /// + /// # Safety + /// /// This should only ever be called with a pointer that was earlier - /// obtained by calling `into_raw` on a `CString`. Additionally, the length - /// of the string will be recalculated from the pointer. + /// obtained by calling `into_raw` on a `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. #[stable(feature = "cstr_memory", since = "1.4.0")] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { let len = libc::strlen(ptr) + 1; // Including the NUL byte -- cgit 1.4.1-3-g733a5 From 313fb8fbf2bd4e99d36286474196599c5a5e6eaf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 19 Sep 2016 14:08:57 +0200 Subject: Replace 'e.g.' by 'i.e.' --- src/libstd/time/duration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 246c57ab238..10a0c567e14 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -83,7 +83,7 @@ impl Duration { /// Returns the number of whole seconds represented by this duration. /// - /// The extra precision represented by this duration is ignored (e.g. extra + /// The extra precision represented by this duration is ignored (i.e. extra /// nanoseconds are not represented in the returned value). #[stable(feature = "duration", since = "1.3.0")] #[inline] @@ -93,7 +93,7 @@ impl Duration { /// /// This method does **not** return the length of the duration when /// represented by nanoseconds. The returned number always represents a - /// fractional portion of a second (e.g. it is less than one billion). + /// fractional portion of a second (i.e. it is less than one billion). #[stable(feature = "duration", since = "1.3.0")] #[inline] pub fn subsec_nanos(&self) -> u32 { self.nanos } -- cgit 1.4.1-3-g733a5