Skip to content

Commit af5a915

Browse files
Fix bounds math issues in tests revealed by quickcheck v1
Some tests relied on unsigned arithmetic that could wrap around, and quickcheck 1.0 was able to reveal the problem. All of the issues were in the tests rather than in the implementation. Fixes #22. Fixes compatibility with quickcheck v1.
1 parent fe1355e commit af5a915

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ mod test {
339339
#[test]
340340
fn check_array_ref_5() {
341341
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
342-
if data.len() < offset + 5 {
342+
if data.len() < 5 || data.len() - 5 < offset {
343343
return quickcheck::TestResult::discard();
344344
}
345345
let out = array_ref!(data, offset, 5);
@@ -351,7 +351,7 @@ mod test {
351351
#[test]
352352
fn check_array_ref_out_of_bounds_5() {
353353
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
354-
if data.len() >= offset + 5 {
354+
if data.len() >= 5 && data.len() - 5 >= offset {
355355
return quickcheck::TestResult::discard();
356356
}
357357
quickcheck::TestResult::must_fail(move || {
@@ -364,7 +364,7 @@ mod test {
364364
#[test]
365365
fn check_array_mut_ref_7() {
366366
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
367-
if data.len() < offset + 7 {
367+
if data.len() < 7 || data.len() - 7 < offset {
368368
return quickcheck::TestResult::discard();
369369
}
370370
let out = array_mut_ref!(data, offset, 7);
@@ -377,7 +377,7 @@ mod test {
377377
#[test]
378378
fn check_array_mut_ref_out_of_bounds_32() {
379379
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
380-
if data.len() >= offset + 32 {
380+
if data.len() >= 32 && data.len() - 32 >= offset {
381381
return quickcheck::TestResult::discard();
382382
}
383383
quickcheck::TestResult::must_fail(move || {

0 commit comments

Comments
 (0)