aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2023-01-21 18:47:35 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2023-01-21 18:47:35 +0100
commitdd95dcd60cc602ea3b3c15fe7f022aada889fea8 (patch)
tree995254d9b738b227633f5e161d406bf5ea88d2d7
parentd16bebaa173789c7371b300b185ebe325596edaf (diff)
downloadfl2k_ampliphase-dd95dcd60cc602ea3b3c15fe7f022aada889fea8.tar.gz
fl2k_ampliphase-dd95dcd60cc602ea3b3c15fe7f022aada889fea8.tar.bz2
fl2k_ampliphase-dd95dcd60cc602ea3b3c15fe7f022aada889fea8.zip
Fix buf length after source read
-rw-r--r--src/main.rs7
1 files 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 <http://www.gnu.org/licenses/>.
*/
+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<T> BufferDumper<T> {
let buf_u8: &[u8] = unsafe {
std::slice::from_raw_parts(
buf.as_ptr() as *const u8,
- buf.len() * std::mem::size_of::<T>()
+ buf.len() * size_of::<T>()
)
};
@@ -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::<i16>()
+ buf.len() * size_of::<i16>()
)
};
@@ -253,7 +254,7 @@ fn main() {
break;
}
}
- buf.resize(len, 0);
+ buf.resize(len / size_of::<i16>(), 0);
},
Err(e) => {
eprintln!("Failed to read source file: {}", e);