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

Issue #22 proposed fix. #23

Closed
wants to merge 1 commit into from
Closed

Issue #22 proposed fix. #23

wants to merge 1 commit into from

Conversation

snakehand
Copy link

Avoid performing logical and on !mask as this will cause a clippy lint error if result is 0.

Reformulate boolean check to os logial or opereations instead.

Avoid performing logical and on !mask as this will cause a clippy lint error if result is 0.

Reformulate boolean check to os logial or opereations instead.
@wrenger
Copy link
Owner

wrenger commented Nov 11, 2023

Thanks for the PR. This check, however, does not entirely catch all cases. Take the following as an example:

#[test]
#[should_panic]
fn negative_pos_overflow() {
    #[bitfield(u32)]
    struct MyBitfield {
        #[bits(3)]
        negative: i32,
        #[bits(29)]
        __: (),
    }
    // 4 is too large for a 3bit singed integer
    MyBitfield::new().with_negative(4); 
}

As for fixing #24, I had to redesign the bounds check entirely.

@wrenger wrenger closed this Nov 11, 2023
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