diff --git a/qcow/src/qcow_raw_file.rs b/qcow/src/qcow_raw_file.rs index 2c56cef23..75836fd22 100644 --- a/qcow/src/qcow_raw_file.rs +++ b/qcow/src/qcow_raw_file.rs @@ -66,7 +66,7 @@ impl QcowRawFile { non_zero_flags: u64, ) -> io::Result<()> { self.file.seek(SeekFrom::Start(offset))?; - let mut buffer = BufWriter::with_capacity(table.len() * size_of::(), &mut self.file); + let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file); for addr in table { let val = if *addr == 0 { 0 @@ -91,7 +91,8 @@ impl QcowRawFile { /// Writes a refcount block to the file. pub fn write_refcount_block(&mut self, offset: u64, table: &[u16]) -> io::Result<()> { self.file.seek(SeekFrom::Start(offset))?; - let mut buffer = BufWriter::with_capacity(table.len() * size_of::(), &mut self.file); + let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file); + for count in table { buffer.write_u16::(*count)?; }