Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix regression with unaligned u8#294

Merged
sharksforarms merged 1 commit into
sharksforarms:masterfrom
wcampbell0x2a:fix-regression-292
Nov 16, 2022
Merged

Fix regression with unaligned u8#294
sharksforarms merged 1 commit into
sharksforarms:masterfrom
wcampbell0x2a:fix-regression-292

Conversation

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator

  • Add logic to fix alignment when needed
  • Add tests for regression testing

See #292

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

Looks like the CI errors for miri occur on master also

@calebfletcher
Copy link
Copy Markdown
Contributor

Thanks for fixing the case for an offset of 4, but it seems like using an offset of 2 still causes it to fail:

let test_data: &[u8] = [0b11000000, 0b00111111].as_ref();

#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "little")]
struct Container {
    #[deku(bits = 2)]
    field1: u8,
    field2: u8,
    #[deku(bits = 6)]
    field3: u8,
}

assert_eq!(
    Container::from_bytes((test_data, 0)).unwrap().1,
    Container {
        field1: 0b11,
        field2: 0,
        field3: 0b111111,
    }
);

Adding in an explicit #[deku(bits = 8)] to field2 causes this case to work as well, so I believe it is likely related.

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

Thanks for fixing the case for an offset of 4, but it seems like using an offset of 2 still causes it to fail:

let test_data: &[u8] = [0b11000000, 0b00111111].as_ref();

#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "little")]
struct Container {
    #[deku(bits = 2)]
    field1: u8,
    field2: u8,
    #[deku(bits = 6)]
    field3: u8,
}

assert_eq!(
    Container::from_bytes((test_data, 0)).unwrap().1,
    Container {
        field1: 0b11,
        field2: 0,
        field3: 0b111111,
    }
);

Adding in an explicit #[deku(bits = 8)] to field2 causes this case to work as well, so I believe it is likely related.

I'll fix this tonight, turns out I was over eager with removing some code and need to align the bits properly. Thanks for catching this.

I'd like to add an aligned attribute or optimization in the future..

* Add logic to fix alignment when needed
* Add tests for regression testing
Copy link
Copy Markdown
Owner

@sharksforarms sharksforarms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wcampbell0x2a, changes and tests look good to me.

@sharksforarms sharksforarms merged commit 1e08426 into sharksforarms:master Nov 16, 2022
@wcampbell0x2a wcampbell0x2a deleted the fix-regression-292 branch December 28, 2023 02:44
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.

3 participants