Skip to content

Commit

Permalink
support start_at that is out of range in the first place (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu authored Sep 28, 2023
1 parent 0ed0188 commit 6b58221
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ipld/amt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ where
match self {
Node::Leaf { vals } => {
let start_idx = start_at.map_or(0, |s| s.saturating_sub(offset));
if start_idx as usize >= vals.len() {
return Ok((false, 0, None));
}
let mut keep_going = true;
for (i, v) in (start_idx..).zip(vals[start_idx as usize..].iter()) {
let idx = offset + i;
Expand All @@ -595,6 +598,9 @@ where
let idx: usize = ((start_at.map_or(0, |s| s.saturating_sub(offset))) / nfh)
.try_into()
.expect("index overflow");
if idx >= links.len() {
return Ok((false, 0, None));
}
for (i, link) in (idx..).zip(links[idx..].iter()) {
if let Some(l) = link {
let offs = offset + (i as u64 * nfh);
Expand Down

0 comments on commit 6b58221

Please sign in to comment.