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

False Positive [E0133] "Access to union field is unsafe" in assigning value to nested union field #10831

Open
Maksim20023 opened this issue Aug 28, 2023 · 0 comments

Comments

@Maksim20023
Copy link
Collaborator

Maksim20023 commented Aug 28, 2023

Environment

  • IntelliJ Rust plugin version: 0.4.200.5421.232
  • Rust toolchain version: 1.71.1
  • IDE name and version: CLion 2023.2.1 Build #CL-232.9559.58, built on August 22, 2023
  • Operating system: macOS 13.4.1

Problem description

Screenshot 2023-08-28 at 17 03 34

Steps to reproduce

Create a new rust project and copy-paste the following code:

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

pub struct BACnet_Application_Data_Value {
    pub type_: BACnet_Application_Data_Value__bindgen_ty_1,
}


pub union BACnet_Application_Data_Value__bindgen_ty_1 {
    pub Special_Event: BACnet_Special_Event,
}

#[derive(Clone, Copy)]
pub struct BACnet_Special_Event {
    pub period: BACnet_Special_Event__bindgen_ty_1,
}


#[derive(Clone, Copy)]
pub union BACnet_Special_Event__bindgen_ty_1 {
    pub calendarReference: BACnet_Object_Id,
}

#[derive(Clone, Copy)]
pub struct BACnet_Object_Id {
    pub type_: u32,
}

fn main() {
    let mut enc: BACnet_Application_Data_Value = unsafe { std::mem::zeroed() };

    // bug here:
    enc.type_.Special_Event.period.calendarReference.type_ = 1;
}

Originally posted here

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

No branches or pull requests

1 participant