File tree 4 files changed +25
-4
lines changed
4 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 22
22
23
23
include :
24
24
# Test MSRV
25
- - rust : 1.60 .0
25
+ - rust : 1.65 .0
26
26
TARGET : x86_64-unknown-linux-gnu
27
27
28
28
# Test nightly but don't fail
53
53
54
54
strategy :
55
55
matrix :
56
- rust : [stable, 1.60 .0]
56
+ rust : [stable, 1.65 .0]
57
57
TARGET : [x86_64-apple-darwin]
58
58
59
59
steps :
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
8
8
9
9
## [ Unreleased]
10
10
11
+ - Prevent underflow panics when using a ` MockI2CDevice ` with an offset of ` 0x0 `
12
+ - Bumps the MSRV to 1.65.0
13
+
11
14
## [ v0.6.0] - 2023-08-03
12
15
13
16
- Hide nix from the public api such that it can be updated without resulting in a breaking change.
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ cross-compile. See <https://github.com/cross-rs/cross> for pointers.
54
54
55
55
## Minimum Supported Rust Version (MSRV)
56
56
57
- This crate is guaranteed to compile on stable Rust 1.60 .0 and up. It * might*
57
+ This crate is guaranteed to compile on stable Rust 1.65 .0 and up. It * might*
58
58
compile with older versions but that may change in any new patch release.
59
59
60
60
## License
Original file line number Diff line number Diff line change 6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
8
use core:: { I2CDevice , I2CMessage , I2CTransfer } ;
9
+ use std:: convert:: TryFrom ;
9
10
use std:: io;
10
11
11
12
/// I2C mock result type
@@ -44,7 +45,12 @@ impl I2CRegisterMap {
44
45
fn read ( & mut self , data : & mut [ u8 ] ) -> I2CResult < ( ) > {
45
46
let len = data. len ( ) ;
46
47
data. clone_from_slice ( & self . registers [ self . offset ..( self . offset + len) ] ) ;
47
- println ! ( "READ | 0x{:X} : {:?}" , self . offset - data. len( ) , data) ;
48
+ println ! (
49
+ "READ | 0x{:X} : {:?}" ,
50
+ isize :: try_from( self . offset) . unwrap_or( 0xBAD )
51
+ - isize :: try_from( data. len( ) ) . unwrap_or( 0xBAD ) ,
52
+ data
53
+ ) ;
48
54
Ok ( ( ) )
49
55
}
50
56
@@ -156,3 +162,15 @@ where
156
162
Ok ( messages. len ( ) as u32 )
157
163
}
158
164
}
165
+
166
+ #[ cfg( test) ]
167
+ mod test {
168
+ use super :: * ;
169
+
170
+ #[ test]
171
+ fn test_can_read_at_zero_offset ( ) {
172
+ let mut mock_device = MockI2CDevice :: new ( ) ;
173
+ mock_device. regmap . write_regs ( 0x0 , & [ 0x1u8 ; 4 ] ) ;
174
+ mock_device. read ( & mut [ 0x0u8 ; 4 ] ) . unwrap ( ) ;
175
+ }
176
+ }
You can’t perform that action at this time.
0 commit comments