about summary refs log tree commit diff
path: root/library/std/src/io
diff options
context:
space:
mode:
authorBenoît du Garreau <benoit@dugarreau.fr>2025-03-28 15:52:15 +0100
committerBenoît du Garreau <benoit@dugarreau.fr>2025-04-01 00:07:59 +0200
commit2feb91181882e525e698c4543063f4d0296fcf91 (patch)
tree542178d145b243f0a13fb0a67dea36b9a890b632 /library/std/src/io
parent0b45675cfcec57f30a3794e1a1e18423aa9cf200 (diff)
downloadrust-2feb91181882e525e698c4543063f4d0296fcf91.tar.gz
rust-2feb91181882e525e698c4543063f4d0296fcf91.zip
io: Avoid marking buffer as uninit when copying to `BufWriter`
Diffstat (limited to 'library/std/src/io')
-rw-r--r--library/std/src/io/copy.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs
index 8d733325b3b..15e962924ac 100644
--- a/library/std/src/io/copy.rs
+++ b/library/std/src/io/copy.rs
@@ -248,8 +248,11 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
                     Err(e) => return Err(e),
                 }
             } else {
+                // All the bytes that were already in the buffer are initialized,
+                // treat them as such when the buffer is flushed.
+                init += buf.len();
+
                 self.flush_buf()?;
-                init = 0;
             }
         }
     }