Skip to content

Commit 6fbe31c

Browse files
authored
[receive] use get() in has_all_pages() instead of unguarded array index (#53)
* refactor has all pages to use get()
1 parent de0edbf commit 6fbe31c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/receive.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,13 @@ impl DiscoveredSacnSource {
13641364
pub fn has_all_pages(&mut self) -> bool {
13651365
// https://rust-lang-nursery.github.io/rust-cookbook/algorithms/sorting.html (31/12/2019)
13661366
self.pages.sort_by(|a, b| a.page.cmp(&b.page));
1367-
for i in 0..(self.last_page + 1) {
1368-
if self.pages[i as usize].page != i {
1367+
for i in 0..=self.last_page {
1368+
if self
1369+
.pages
1370+
.get(i as usize)
1371+
.map(|p| p.page != i)
1372+
.unwrap_or(true)
1373+
{
13691374
return false;
13701375
}
13711376
}

0 commit comments

Comments
 (0)