File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -83,21 +83,28 @@ impl<I: Write> BufferedCopySpec for BufWriter<I> {
83
83
}
84
84
85
85
let mut len = 0 ;
86
+ let mut init = 0 ;
86
87
87
88
loop {
88
89
let buf = writer. buffer_mut ( ) ;
89
90
let mut read_buf = ReadBuf :: uninit ( buf. spare_capacity_mut ( ) ) ;
90
91
92
+ // SAFETY: init is either 0 or the initialized_len of the previous iteration
93
+ unsafe {
94
+ read_buf. assume_init ( init) ;
95
+ }
96
+
91
97
if read_buf. capacity ( ) >= DEFAULT_BUF_SIZE {
92
98
match reader. read_buf ( & mut read_buf) {
93
- //Ok(0) => return Ok(len), // EOF reached
94
99
Ok ( ( ) ) => {
95
100
let bytes_read = read_buf. filled_len ( ) ;
96
101
97
102
if bytes_read == 0 {
98
103
return Ok ( len) ;
99
104
}
100
105
106
+ init = read_buf. initialized_len ( ) ;
107
+
101
108
// SAFETY: ReadBuf guarantees all of its filled bytes are init
102
109
unsafe { buf. set_len ( buf. len ( ) + bytes_read) } ;
103
110
len += bytes_read as u64 ;
You can’t perform that action at this time.
0 commit comments