Skip to content

Commit 3e93493

Browse files
committed
fix undefined behaviour
1 parent fd2f2a4 commit 3e93493

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/crc.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use crate::rcc::{Enable, Rcc, Reset};
2020
use crate::stm32::CRC;
2121
use core::hash::Hasher;
22-
use core::ptr;
2322

2423
/// Extension trait to constrain the CRC peripheral.
2524
pub trait CrcExt {
@@ -170,11 +169,8 @@ impl Crc {
170169
pub fn feed(&mut self, data: &[u8]) {
171170
let crc = unsafe { &(*CRC::ptr()) };
172171
for byte in data {
173-
unsafe {
174-
// Workaround with svd2rust, it does not generate the byte interface to the DR
175-
// register
176-
ptr::write_volatile(&crc.dr as *const _ as *mut u8, *byte);
177-
}
172+
let ptr = &crc.dr as *const _;
173+
unsafe { core::ptr::write_volatile(ptr as *mut u8, *byte) };
178174
}
179175
}
180176

src/spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ macro_rules! spi {
262262
} else if sr.crcerr().bit_is_set() {
263263
nb::Error::Other(Error::Crc)
264264
} else if sr.txe().bit_is_set() {
265-
// NOTE(write_volatile) see note above
266-
unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
265+
let ptr = &self.spi.dr as *const _;
266+
unsafe { core::ptr::write_volatile(ptr as *mut u8, byte) };
267267
return Ok(());
268268
} else {
269269
nb::Error::WouldBlock

0 commit comments

Comments
 (0)