@@ -63,6 +63,13 @@ impl InputData {
63
63
}
64
64
Some ( & self . data [ old_pos..old_pos + len] )
65
65
}
66
+ fn get_slice_nonadvancing ( & self , len : usize ) -> Option < & [ u8 ] > {
67
+ let old_pos = self . read_pos . load ( Ordering :: Acquire ) ;
68
+ if self . data . len ( ) < old_pos + len {
69
+ return None ;
70
+ }
71
+ Some ( & self . data [ old_pos..old_pos + len] )
72
+ }
66
73
}
67
74
68
75
struct DummyChainWatcher {
@@ -94,23 +101,23 @@ impl ChainWatchInterface for DummyChainWatcher {
94
101
pub fn do_test ( data : & [ u8 ] ) {
95
102
reset_rng_state ( ) ;
96
103
97
- let mut read_pos = 0 ;
104
+ let input = Arc :: new ( InputData {
105
+ data : data. to_vec ( ) ,
106
+ read_pos : AtomicUsize :: new ( 0 ) ,
107
+ } ) ;
98
108
macro_rules! get_slice_nonadvancing {
99
109
( $len: expr) => {
100
- {
101
- if data. len( ) < read_pos + $len as usize {
102
- return ;
103
- }
104
- & data[ read_pos..read_pos + $len as usize ]
110
+ match input. get_slice_nonadvancing( $len as usize ) {
111
+ Some ( slice) => slice,
112
+ None => return ,
105
113
}
106
114
}
107
115
}
108
116
macro_rules! get_slice {
109
117
( $len: expr) => {
110
- {
111
- let res = get_slice_nonadvancing!( $len) ;
112
- read_pos += $len;
113
- res
118
+ match input. get_slice( $len as usize ) {
119
+ Some ( slice) => slice,
120
+ None => return ,
114
121
}
115
122
}
116
123
}
@@ -153,12 +160,8 @@ pub fn do_test(data: &[u8]) {
153
160
}
154
161
155
162
let logger: Arc < Logger > = Arc :: new ( test_logger:: TestLogger { } ) ;
156
- let input = Arc :: new ( InputData {
157
- data : data. to_vec ( ) ,
158
- read_pos : AtomicUsize :: new ( 0 ) ,
159
- } ) ;
160
163
let chain_monitor = Arc :: new ( DummyChainWatcher {
161
- input : input,
164
+ input : Arc :: clone ( & input) ,
162
165
} ) ;
163
166
164
167
let our_pubkey = get_pubkey ! ( ) ;
0 commit comments