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

transpose: Fix invalid_reference_casting errors #649

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Apr 25, 2024

Fixes this build error with current Rust nightly:

error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
   --> imageflow_core/src/graphics/transpose.rs:122:13
    |
122 |                *(&mut *(*to).pixels.offset(
    |   _____________^______-
    |  |_____________|
    | ||
123 | ||                 x.wrapping_mul(4u32)
124 | ||                     .wrapping_add(y.wrapping_mul((*to).stride)) as isize,
125 | ||             ) as *mut libc::c_uchar as *mut u32) = *(&mut *(*from).pixels.offset(
    | ||_____________- backing allocation comes from here
...   |
128 | |              ) as *mut libc::c_uchar
129 | |                  as *mut u32);
    | |_____________________________^
    |
    = note: casting from `u8` (1 bytes) to `u32` (4 bytes)
    = note: `#[deny(invalid_reference_casting)]` on by default

Fixes this build error with current Rust nightly:

    error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
       --> imageflow_core/src/graphics/transpose.rs:122:13
        |
    122 |                *(&mut *(*to).pixels.offset(
        |   _____________^______-
        |  |_____________|
        | ||
    123 | ||                 x.wrapping_mul(4u32)
    124 | ||                     .wrapping_add(y.wrapping_mul((*to).stride)) as isize,
    125 | ||             ) as *mut libc::c_uchar as *mut u32) = *(&mut *(*from).pixels.offset(
        | ||_____________- backing allocation comes from here
    ...   |
    128 | |              ) as *mut libc::c_uchar
    129 | |                  as *mut u32);
        | |_____________________________^
        |
        = note: casting from `u8` (1 bytes) to `u32` (4 bytes)
        = note: `#[deny(invalid_reference_casting)]` on by default

Signed-off-by: Anders Kaseorg <[email protected]>
@lilith lilith merged commit 058c3a9 into imazen:main Apr 25, 2024
8 checks passed
@andersk andersk deleted the invalid_reference_casting branch April 25, 2024 00:39
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.

2 participants