rust-embedded / rust-i2cdev

Rust library for interfacing with i2c devices under Linux
Apache License 2.0
205 stars 53 forks source link

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

Closed chiefnoah closed 8 months ago

chiefnoah commented 8 months ago

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 commented 8 months ago

How does that look?

chiefnoah commented 8 months ago

Done.