Skip to content

UB in SPI and Serial code #304

Closed
Closed
@TheZoq2

Description

@TheZoq2

@repnop pointed out to me that https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/spi.rs#L261 and the write_volatilecall in serial.rs is UB because constructing (or possibly writing) from a pointer created from a non-mut reference is UB.

A fix might be to just change it to

unsafe { ptr::write_volatile(&mut self.spi.dr as *const _ as *mut FrameSize, data) }

But spi.dr does not implement DerefMut so this fix does not compile. I don't have time to look into it deeper than that today but we should be aware of this potential UB.

Edit: Removed a reference to an unrelated issue
Edit2: Removed the svd2rust part as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions