hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
171 stars 17 forks source link

Use wrapping_shr to prevent overflow #38

Closed sfleener closed 1 year ago

sfleener commented 1 year ago

Fixes #36, I wasn't 100% sure on the test structure so I followed a few existing ones.

hecatia-elegua commented 1 year ago

Thank you. The test structure is okay, though you can just use the issue code (right now, FillsU8 is a u32 haha).

Now, I'm only wondering if https://github.com/hecatia-elegua/bilge/blob/1dfb6cf7d278d102d3f96ac31a9374e2b27fafc7/bilge-impl/src/try_from_bits.rs#L99 can trigger this bug as well. Maybe this is optimized away by the compiler, because I can't seem to hit this with something like #[..] struct Wrapper2 {foo: u8}. Let's just change it there as well, anyways.

sfleener commented 1 year ago

Sounds good, I found one more spot that seems like it could be triggered by this class of bug but I also couldn't get a repro working with it. Seems reasonable to update that as well.