From 866878ea5314716f439123449192a9dbf88a9ad1 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 30 Jan 2024 19:08:22 +0100 Subject: [PATCH] Replace UB code by a legitimate pointer access Using such a cast to set the `dr` register inside an `unsafe` block is an acceptable way to access the data. --- CHANGELOG.md | 1 + src/spi.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43acf6e2..42223f86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/spi.rs b/src/spi.rs index f32e373c..74ad0083 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -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