Merge pull request #29 from Olssdani/fix_out_of_bound_index

Fixed crash because of out of bound indices for MaxiCode.
This commit is contained in:
Henry A Schimke
2023-03-21 09:46:59 -05:00
committed by GitHub
2 changed files with 6 additions and 3 deletions

View File

@@ -255,7 +255,7 @@ impl BitMatrix {
/// Confusingly returns true if the requested element is out of bounds /// Confusingly returns true if the requested element is out of bounds
pub fn check_in_bounds(&self, x: u32, y: u32) -> bool { pub fn check_in_bounds(&self, x: u32, y: u32) -> bool {
(self.get_offset(y, x)) > self.bits.len() (self.get_offset(y, x)) >= self.bits.len()
} }
/** /**

View File

@@ -281,7 +281,9 @@ impl Circle<'_> {
// count left // count left
while { while {
let point = get_point(self.center, (x, y), rotation); let point = get_point(self.center, (x, y), rotation);
!self.image.get(point.x as u32, point.y as u32) && x > 0 !self.image.check_in_bounds(point.x as u32, point.y as u32)
&& !self.image.get(point.x as u32, point.y as u32)
&& x > 0
} { } {
x -= 1; x -= 1;
length += 1; length += 1;
@@ -293,7 +295,8 @@ impl Circle<'_> {
// count right // count right
while { while {
let point = get_point(self.center, (x, y), rotation); let point = get_point(self.center, (x, y), rotation);
!self.image.get(point.x as u32, point.y as u32) !self.image.check_in_bounds(point.x as u32, point.y as u32)
&& !self.image.get(point.x as u32, point.y as u32)
} { } {
x += 1; x += 1;
length += 1; length += 1;