Skip to content

Commit

Permalink
Replace UB code by a legitimate pointer access
Browse files Browse the repository at this point in the history
Using such a cast to set the `dr` register inside an `unsafe` block is
an acceptable way to access the data.
  • Loading branch information
samueltardieu committed Jan 30, 2024
1 parent 773836d commit 866878e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Move from bors/manual merge to GH merge queue
- Add tools/check.py python script for local check
- Add changelog check on PRs
- Replace UB code by a legitimate pointer access

## [v0.10.0] - 2022-12-12

Expand Down
2 changes: 1 addition & 1 deletion src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ where

fn write_data_reg(&mut self, data: FrameSize) {
// NOTE(write_volatile) see note above
unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut FrameSize, data) }
unsafe { ptr::write_volatile(ptr::addr_of!(self.spi.dr) as *mut FrameSize, data) }
}

// Implement write as per the "Transmit only procedure" page 712
Expand Down

0 comments on commit 866878e

Please sign in to comment.