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

Prevent underflow when using a MockI2CDevice with a RegisterMap.offset = 0x0 #83

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

chiefnoah
Copy link

Cast both the offset and the slice.len() to isize so we can safely underflow to a negative number. We lose out on 1-bit of possible offset/slice size, but I'd love to have your computer if you're bumping into that.

Adds a quick test to verify the fix as well.

This fixes #77.

@chiefnoah chiefnoah requested a review from a team as a code owner January 17, 2024 18:08
Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

Thank you!
Could you rather do the conversion via: isize::try_from(self.offset).unwrap_or(0xBAD) or similar?

It is not very important because it is just a print in a mock, but it would be nicer to see "BAD" rather than "FFFFFFFFFFFFFFFF".

@chiefnoah
Copy link
Author

How does that look?

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!
Could you also add an entry to the changelog?
Could you also raise the MSRV to 1.65.0 and note it in the changelog as well?

@chiefnoah
Copy link
Author

Done.

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@eldruin eldruin added this pull request to the merge queue Jan 18, 2024
Merged via the queue into rust-embedded:master with commit bd5f200 Jan 18, 2024
8 checks passed
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.

smbus_read_word_data() on MockI2CDevice fails at address 0x00
2 participants