-
Notifications
You must be signed in to change notification settings - Fork 344
Fix bound checking in the NorFlash::erase implementation of FlashRegion #4055
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
if !self.range().contains(&address_to) { | ||
if !address_to <= self.range().end { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be !(address_to <= self.range().end)
or even better address_to > self.range().end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad
Thanks! Ideally, we would add tests for this but that would require implementing NorFlash for MockFlash the |
According to the documentation:
That's a closed-closed interval. Is our current check really incorrect? |
Allow the exclusive address_to to be equal to the exclusive upper bound of a partition.
The |
Maybe we should then ask for clarification on the documentation, instead of guessing something and risking doing the wrong thing. This may be a case where the rest of our implementation is wrong, but the documentation is right. If we don't know, we shouldn't change behaviour. I guess the helper is a good hint, IMO we still should be sure. |
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
address_to
could be just past the range, being exactly equal to the end that is exclusive.Testing
I configured littlefs to use
partition size / erase size
blocks, and got anOutOfBounds
error when it tried to erase the last block.