Skip to content

Commit 632ee45

Browse files
committed
use checked indexing
1 parent f6de9ed commit 632ee45

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

program/rust/src/validator.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@ pub fn compute_publisher_stake_caps<'a>(
170170
.checked_div(max(u64::from(price_account.num_), z))
171171
.unwrap_or(0);
172172
for i in 0..(price_account.num_ as usize) {
173-
publisher_caps
174-
.entry(price_account.comp_[i].pub_)
175-
.and_modify(|e: &mut u64| *e = e.saturating_add(cap))
176-
.or_insert(cap);
173+
if let Some(pub_) = price_account.comp_.get(i).map(|comp| &comp.pub_) {
174+
publisher_caps
175+
.entry(*pub_)
176+
.and_modify(|e: &mut u64| *e = e.saturating_add(cap))
177+
.or_insert(cap);
178+
}
177179
}
178180
}
179181
}

0 commit comments

Comments
 (0)