Skip to content

Commit 94b6df6

Browse files
authored
fs: fill the destination buffer with 0s for MockFile::read() (#7596)
1 parent 510b9ea commit 94b6df6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tokio/src/fs/mocks.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ mock! {
5656

5757
impl Read for MockFile {
5858
fn read(&mut self, dst: &mut [u8]) -> io::Result<usize> {
59+
// Placate Miri. Tokio will call this method with an uninitialized
60+
// buffer, which is ok because std::io::Read::read implementations don't usually read
61+
// from their input buffers. But Mockall 0.12-0.13 will try to Debug::fmt the
62+
// buffer, even if there is no failure, triggering an uninitialized data access alert from
63+
// Miri. Initialize the data here just to prevent those Miri alerts.
64+
// This can be removed after upgrading to Mockall 0.14.
65+
dst.fill(0);
5966
self.inner_read(dst)
6067
}
6168
}

0 commit comments

Comments
 (0)