@@ -339,7 +339,9 @@ mod test {
339
339
#[ test]
340
340
fn check_array_ref_5 ( ) {
341
341
fn f ( data : Vec < u8 > , offset : usize ) -> quickcheck:: TestResult {
342
- if data. len ( ) < offset + 5 {
342
+ // Compute the following, with correct results even if the sum would overflow:
343
+ // if data.len() < offset + 5
344
+ if data. len ( ) < 5 || data. len ( ) - 5 < offset {
343
345
return quickcheck:: TestResult :: discard ( ) ;
344
346
}
345
347
let out = array_ref ! ( data, offset, 5 ) ;
@@ -351,7 +353,9 @@ mod test {
351
353
#[ test]
352
354
fn check_array_ref_out_of_bounds_5 ( ) {
353
355
fn f ( data : Vec < u8 > , offset : usize ) -> quickcheck:: TestResult {
354
- if data. len ( ) >= offset + 5 {
356
+ // Compute the following, with correct results even if the sum would overflow:
357
+ // if data.len() >= offset + 5
358
+ if data. len ( ) >= 5 && data. len ( ) - 5 >= offset {
355
359
return quickcheck:: TestResult :: discard ( ) ;
356
360
}
357
361
quickcheck:: TestResult :: must_fail ( move || {
@@ -364,7 +368,9 @@ mod test {
364
368
#[ test]
365
369
fn check_array_mut_ref_7 ( ) {
366
370
fn f ( mut data : Vec < u8 > , offset : usize ) -> quickcheck:: TestResult {
367
- if data. len ( ) < offset + 7 {
371
+ // Compute the following, with correct results even if the sum would overflow:
372
+ // if data.len() < offset + 7
373
+ if data. len ( ) < 7 || data. len ( ) - 7 < offset {
368
374
return quickcheck:: TestResult :: discard ( ) ;
369
375
}
370
376
let out = array_mut_ref ! ( data, offset, 7 ) ;
@@ -377,7 +383,9 @@ mod test {
377
383
#[ test]
378
384
fn check_array_mut_ref_out_of_bounds_32 ( ) {
379
385
fn f ( mut data : Vec < u8 > , offset : usize ) -> quickcheck:: TestResult {
380
- if data. len ( ) >= offset + 32 {
386
+ // Compute the following, with correct results even if the sum would overflow:
387
+ // if data.len() >= offset + 32
388
+ if data. len ( ) >= 32 && data. len ( ) - 32 >= offset {
381
389
return quickcheck:: TestResult :: discard ( ) ;
382
390
}
383
391
quickcheck:: TestResult :: must_fail ( move || {
0 commit comments