From dd95dcd60cc602ea3b3c15fe7f022aada889fea8 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 21 Jan 2023 18:47:35 +0100 Subject: Fix buf length after source read --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 825d4e1..fc35c58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ * along with this program. If not, see . */ +use std::mem::size_of; use std::sync::atomic::{AtomicBool, Ordering}; use std::{env, thread}; use std::io::{prelude::*, BufReader, BufWriter}; @@ -59,7 +60,7 @@ impl BufferDumper { let buf_u8: &[u8] = unsafe { std::slice::from_raw_parts( buf.as_ptr() as *const u8, - buf.len() * std::mem::size_of::() + buf.len() * size_of::() ) }; @@ -241,7 +242,7 @@ fn main() { let mut buf_u8: &mut [u8] = unsafe { std::slice::from_raw_parts_mut( buf.as_mut_ptr() as *mut u8, - buf.len() * std::mem::size_of::() + buf.len() * size_of::() ) }; @@ -253,7 +254,7 @@ fn main() { break; } } - buf.resize(len, 0); + buf.resize(len / size_of::(), 0); }, Err(e) => { eprintln!("Failed to read source file: {}", e); -- cgit v1.2.3