Skip to content

Commit 36e1b4c

Browse files
authored
Merge pull request #28 from musicinmybrain/quickcheck-v1
Fix some bounds-arithmetic flaws in the tests, and update to quickcheck v1
2 parents 35d71c6 + fd823d5 commit 36e1b4c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ repository = "https://github.com/droundy/arrayref"
88
documentation = "https://docs.rs/arrayref"
99

1010
[dev-dependencies]
11-
quickcheck = "0.6"
11+
quickcheck = "1.0"

src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ 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+
// 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 {
343345
return quickcheck::TestResult::discard();
344346
}
345347
let out = array_ref!(data, offset, 5);
@@ -351,7 +353,9 @@ mod test {
351353
#[test]
352354
fn check_array_ref_out_of_bounds_5() {
353355
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 {
355359
return quickcheck::TestResult::discard();
356360
}
357361
quickcheck::TestResult::must_fail(move || {
@@ -364,7 +368,9 @@ mod test {
364368
#[test]
365369
fn check_array_mut_ref_7() {
366370
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 {
368374
return quickcheck::TestResult::discard();
369375
}
370376
let out = array_mut_ref!(data, offset, 7);
@@ -377,7 +383,9 @@ mod test {
377383
#[test]
378384
fn check_array_mut_ref_out_of_bounds_32() {
379385
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 {
381389
return quickcheck::TestResult::discard();
382390
}
383391
quickcheck::TestResult::must_fail(move || {

0 commit comments

Comments
 (0)