Skip to content

Commit 2664094

Browse files
committed
Modify the concentric finder to guard array bounds
A potential resolution to Issue #36. In some cases the array positions suggested by the corner_positions array may be out of bounds for the points array. To resolve this, guard against out of bounds checks. In other cases, where the positions are matched, guard against having the start position of a slice go beyond the end position of the slice.
1 parent 62e49b3 commit 2664094

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/common/cpp_essentials/concentric_finder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
389389
let try_get_range = |a: usize, b: usize| -> Option<&[Point]> {
390390
if a > b {
391391
None
392+
}
393+
// Added for Issue #36 where array is sometimes out of bounds
394+
else if a + 1 >= points.len() || b >= points.len() {
395+
if a + 1 >= points.len() {
396+
None
397+
} else {
398+
Some(&points[a..])
399+
}
400+
}
401+
// Added for Issue #36 where a sometimes equals b
402+
else if a == b {
403+
Some(&points[a..b])
392404
} else {
393405
Some(&points[a + 1..b])
394406
}

0 commit comments

Comments
 (0)