Skip to content

Commit

Permalink
Modify the concentric finder to guard array bounds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hschimke committed Nov 6, 2023
1 parent 62e49b3 commit 2664094
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/common/cpp_essentials/concentric_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
let try_get_range = |a: usize, b: usize| -> Option<&[Point]> {
if a > b {
None
}
// Added for Issue #36 where array is sometimes out of bounds
else if a + 1 >= points.len() || b >= points.len() {
if a + 1 >= points.len() {
None
} else {
Some(&points[a..])
}
}
// Added for Issue #36 where a sometimes equals b
else if a == b {
Some(&points[a..b])
} else {
Some(&points[a + 1..b])
}
Expand Down

0 comments on commit 2664094

Please sign in to comment.