File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ pub unsafe trait BufMut {
33
33
/// This value is greater than or equal to the length of the slice returned
34
34
/// by `chunk_mut()`.
35
35
///
36
+ /// Writing to a `BufMut` may involve allocating more memory on the fly.
37
+ /// Implementations may fail before reaching the number of bytes indicated
38
+ /// by this method if they encounter an allocation failure.
39
+ ///
36
40
/// # Examples
37
41
///
38
42
/// ```
@@ -158,6 +162,9 @@ pub unsafe trait BufMut {
158
162
/// `chunk_mut()` returning an empty slice implies that `remaining_mut()` will
159
163
/// return 0 and `remaining_mut()` returning 0 implies that `chunk_mut()` will
160
164
/// return an empty slice.
165
+ ///
166
+ /// This function may trigger an out-of-memory abort if it tries to allocate
167
+ /// memory and fails to do so.
161
168
// The `chunk_mut` method was previously called `bytes_mut`. This alias makes the
162
169
// rename more easily discoverable.
163
170
#[ cfg_attr( docsrs, doc( alias = "bytes_mut" ) ) ]
@@ -1025,7 +1032,8 @@ unsafe impl BufMut for &mut [u8] {
1025
1032
unsafe impl BufMut for Vec < u8 > {
1026
1033
#[ inline]
1027
1034
fn remaining_mut ( & self ) -> usize {
1028
- usize:: MAX - self . len ( )
1035
+ // A vector can never have more than isize::MAX bytes
1036
+ core:: isize:: MAX as usize - self . len ( )
1029
1037
}
1030
1038
1031
1039
#[ inline]
Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ use core::usize;
9
9
fn test_vec_as_mut_buf ( ) {
10
10
let mut buf = Vec :: with_capacity ( 64 ) ;
11
11
12
- assert_eq ! ( buf. remaining_mut( ) , usize :: MAX ) ;
12
+ assert_eq ! ( buf. remaining_mut( ) , isize :: MAX as usize ) ;
13
13
14
14
assert ! ( buf. chunk_mut( ) . len( ) >= 64 ) ;
15
15
16
16
buf. put ( & b"zomg" [ ..] ) ;
17
17
18
18
assert_eq ! ( & buf, b"zomg" ) ;
19
19
20
- assert_eq ! ( buf. remaining_mut( ) , usize :: MAX - 4 ) ;
20
+ assert_eq ! ( buf. remaining_mut( ) , isize :: MAX as usize - 4 ) ;
21
21
assert_eq ! ( buf. capacity( ) , 64 ) ;
22
22
23
23
for _ in 0 ..16 {
You can’t perform that action at this time.
0 commit comments