Skip to content

Commit aced046

Browse files
committed
fix autd3-firmware-emulator by miri test
1 parent 2189c10 commit aced046

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

autd3-firmware-emulator/src/cpu/emulator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ impl CPUEmulator {
141141
}
142142

143143
impl CPUEmulator {
144-
pub(crate) const fn cast<T>(data: &[u8]) -> &T {
145-
unsafe { &*(data.as_ptr() as *const T) }
144+
pub(crate) const fn cast<T>(data: &[u8]) -> T {
145+
unsafe { (data.as_ptr() as *const T).read_unaligned() }
146146
}
147147

148148
const fn get_addr(select: u8, addr: u16) -> u16 {

autd3-firmware-emulator/src/cpu/operation/clear.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use crate::{cpu::params::*, CPUEmulator};
22

3+
#[allow(dead_code)]
34
#[repr(C, align(2))]
45
struct Clear {
56
tag: u8,
67
}
78

89
impl CPUEmulator {
9-
pub(crate) unsafe fn clear(&mut self, data: &[u8]) -> u8 {
10-
let _d = Self::cast::<Clear>(data);
10+
pub(crate) unsafe fn clear(&mut self, _data: &[u8]) -> u8 {
11+
// let _d = Self::cast::<Clear>(data);
1112

1213
self.read_fpga_state = false;
1314

autd3-firmware-emulator/src/cpu/operation/gain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl CPUEmulator {
2424
let data = unsafe {
2525
std::slice::from_raw_parts(
2626
data[std::mem::size_of::<Gain>()..].as_ptr() as *const u16,
27-
(data.len() - 2) >> 1,
27+
self.num_transducers,
2828
)
2929
};
3030

autd3-firmware-emulator/src/fpga/emulator/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Memory {
101101
}
102102

103103
pub fn read_bram_as<T>(bram: &[u16], addr: usize) -> T {
104-
unsafe { (bram.as_ptr().add(addr) as *const T).read() }
104+
unsafe { (bram.as_ptr().add(addr) as *const T).read_unaligned() }
105105
}
106106

107107
pub fn write(&mut self, addr: u16, data: u16) {

0 commit comments

Comments
 (0)