We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
BufWriter
BorrowedBuf::set_init
1 parent 12f35ad commit d2dc330Copy full SHA for d2dc330
1 file changed
library/std/src/io/copy.rs
@@ -219,9 +219,11 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
219
loop {
220
let buf = self.buffer_mut();
221
let mut read_buf: BorrowedBuf<'_> = buf.spare_capacity_mut().into();
222
-
223
if init {
224
- // SAFETY: init is either 0 or the init_len from the previous iteration.
+ // SAFETY: `init` is only true after `reader` initializes `read_buf`.
+ // `flush_buf` won't cause any part of the spare capacity to become uninitialized or
225
+ // cause `self.buf` to reallocate, so it is OK to persist this across `flush_buf`
226
+ // calls. FIXME: This seems like a dangerous assumption.
227
unsafe { read_buf.set_init() };
228
}
229
0 commit comments