mozilla / audioipc

Cubeb Audio Remoting For Gecko
10 stars 17 forks source link

New clippy issues about alignment size #103

Closed padenot closed 3 years ago

padenot commented 4 years ago
error: casting from `*const u8` to a more-strictly-aligned pointer (`*const i32`) (1 < 4 bytes)
  --> audioipc/src/cmsg.rs:20:40
   |
20 |         unsafe { slice::from_raw_parts(self.fds.as_ptr() as *const _, n) }
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[deny(clippy::cast_ptr_alignment)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment

error: casting from `*const u8` to a more-strictly-aligned pointer (`*const libc::unix::bsd::cmsghdr`) (1 < 4 bytes)
  --> audioipc/src/cmsg.rs:55:45
   |
55 |             let cmsg: &cmsghdr = unsafe { &*(control.as_ptr() as *const _) };
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment

error: casting from `*mut u8` to a more-strictly-aligned pointer (`*const libc::unix::bsd::cmsghdr`) (1 < 4 bytes)
   --> audioipc/src/cmsg.rs:128:53
    |
128 |                 let cmsg_data_ptr = libc::CMSG_DATA(cmsghdr_ptr as _);
    |                                                     ^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment

I don't know if this is problematic in practice.

kinetiknz commented 4 years ago

We rely on the underlying buffer to be aligned correctly by the allocator. I don't believe there's a real issue here, but it'd be worth clarifying by adding asserts rather than just disabling the lint.

kinetiknz commented 3 years ago

clippy will be enabled on CI by default via https://github.com/mozilla/audioipc-2/pull/118

These warnings no longer appear with the default clippy config. Given that and my previous comment, I'll close this.