@@ -34,6 +34,7 @@ use cmp::Ordering::{self, Less, Equal, Greater};
34
34
use cmp;
35
35
use fmt;
36
36
use intrinsics:: assume;
37
+ use isize;
37
38
use iter:: * ;
38
39
use ops:: { FnMut , Try , self } ;
39
40
use option:: Option ;
@@ -3880,6 +3881,8 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
3880
3881
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3881
3882
pub unsafe fn from_raw_parts < ' a , T > ( data : * const T , len : usize ) -> & ' a [ T ] {
3882
3883
debug_assert ! ( data as usize % mem:: align_of:: <T >( ) == 0 , "attempt to create unaligned slice" ) ;
3884
+ debug_assert ! ( len * mem:: size_of:: <T >( ) <= isize :: MAX as usize ,
3885
+ "attempt to create slice covering half the address space" ) ;
3883
3886
Repr { raw : FatPtr { data, len } } . rust
3884
3887
}
3885
3888
@@ -3889,14 +3892,20 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
3889
3892
/// This function is unsafe for the same reasons as [`from_raw_parts`], as well
3890
3893
/// as not being able to provide a non-aliasing guarantee of the returned
3891
3894
/// mutable slice. `data` must be non-null and aligned even for zero-length
3892
- /// slices as with [`from_raw_parts`]. See the documentation of
3893
- /// [`from_raw_parts`] for more details.
3895
+ /// slices as with [`from_raw_parts`]. The total size of the slice must be no
3896
+ /// larger than `isize::MAX` **bytes** in memory. See the safety documentation
3897
+ /// of [`pointer::offset`].
3898
+ ///
3899
+ /// See the documentation of [`from_raw_parts`] for more details.
3894
3900
///
3895
3901
/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
3902
+ /// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset
3896
3903
#[ inline]
3897
3904
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3898
3905
pub unsafe fn from_raw_parts_mut < ' a , T > ( data : * mut T , len : usize ) -> & ' a mut [ T ] {
3899
3906
debug_assert ! ( data as usize % mem:: align_of:: <T >( ) == 0 , "attempt to create unaligned slice" ) ;
3907
+ debug_assert ! ( len * mem:: size_of:: <T >( ) <= isize :: MAX as usize ,
3908
+ "attempt to create slice covering half the address space" ) ;
3900
3909
Repr { raw : FatPtr { data, len} } . rust_mut
3901
3910
}
3902
3911
0 commit comments