Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace UB code by a legitimate pointer access #480

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Jan 30, 2024

This removes a compilation error due to the invalid-reference-casting check.

@adamgreig
Copy link
Member

In this case the error is legit and the code has UB. It should be updated to at least use &mut self.spi.dr as *mut FrameSize to avoid casting a shared reference to a mutable pointer. Better yet is to use addr_of!() as was done here: stm32-rs/stm32f0xx-hal#170

@samueltardieu samueltardieu changed the title Silent a Rust compiler warning on invalid reference casting Replace UB code by a legitimate pointer access Jan 30, 2024
@samueltardieu
Copy link
Contributor Author

In this case the error is legit and the code has UB. It should be updated to at least use &mut self.spi.dr as *mut FrameSize to avoid casting a shared reference to a mutable pointer. Better yet is to use addr_of!() as was done here: stm32-rs/stm32f0xx-hal#170

addr_of!() is the way to go, &mut is not possible here as DerefMut is not implemented.

@burrbull burrbull added this pull request to the merge queue Jan 30, 2024
Merged via the queue into stm32-rs:master with commit 2c10000 Jan 30, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants