Skip to content

Commit fd823d5

Browse files
Add explanatory comments to weird overflow-proof conditionals
1 parent e0fea6b commit fd823d5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ mod test {
339339
#[test]
340340
fn check_array_ref_5() {
341341
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
342+
// Compute the following, with correct results even if the sum would overflow:
343+
// if data.len() < offset + 5
342344
if data.len() < 5 || data.len() - 5 < offset {
343345
return quickcheck::TestResult::discard();
344346
}
@@ -351,6 +353,8 @@ mod test {
351353
#[test]
352354
fn check_array_ref_out_of_bounds_5() {
353355
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
356+
// Compute the following, with correct results even if the sum would overflow:
357+
// if data.len() >= offset + 5
354358
if data.len() >= 5 && data.len() - 5 >= offset {
355359
return quickcheck::TestResult::discard();
356360
}
@@ -364,6 +368,8 @@ mod test {
364368
#[test]
365369
fn check_array_mut_ref_7() {
366370
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
371+
// Compute the following, with correct results even if the sum would overflow:
372+
// if data.len() < offset + 7
367373
if data.len() < 7 || data.len() - 7 < offset {
368374
return quickcheck::TestResult::discard();
369375
}
@@ -377,6 +383,8 @@ 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 {
386+
// Compute the following, with correct results even if the sum would overflow:
387+
// if data.len() >= offset + 32
380388
if data.len() >= 32 && data.len() - 32 >= offset {
381389
return quickcheck::TestResult::discard();
382390
}

0 commit comments

Comments
 (0)