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