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

pad_XXX/align_XX attributes write unexpected zeros. #295

Open
ismell opened this issue Oct 29, 2024 · 0 comments
Open

pad_XXX/align_XX attributes write unexpected zeros. #295

ismell opened this issue Oct 29, 2024 · 0 comments
Labels
confusing-api Oops! Confusion occurred documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@ismell
Copy link

ismell commented Oct 29, 2024

Take the following:

pub struct BootImage {
    pub header: BootImageHeader,

    // Skip reading the individual ramdisk fragments.
    #[brw(pad_size_to = header.ramdisk_size, align_after = header.page_size)]
    pub ramdisk_fragments: (),
   
   ...
}

I'm reading BootImage from a file, changing a couple properties, and writing BootImage back to the same file. I was surprised to find out that the ramdisk_fragments part of my file was all zeros. I wanted to skip reading/writing the ramdisk_fragments since it's not relevant to my use case.

Reading the documentation for align_before, align_after, and pad_size_to, it says "Aligns the reader/writer to the Nth byte before a field." and "Ensures the reader/writer is always advanced at least N bytes.". It doesn't mention that it zero fills the space. Reading the pad_after function shows the zeroing code.

I doubt we can change the behavior at this point, but maybe we can update the documentation?

I can work around my issue by using seek_before, it just makes the struct less readable.

Thanks!

@csnover csnover added documentation Improvements or additions to documentation good first issue Good for newcomers confusing-api Oops! Confusion occurred labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confusing-api Oops! Confusion occurred documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants