Skip to content

Commit

Permalink
Fix getNext(unkown)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Dec 14, 2022
1 parent 0cd6790 commit 1702aac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contracts/HeapOrdering.sol
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ library HeapOrdering {
/// @return The address of the next account.
function getNext(HeapArray storage _heap, address _id) internal view returns (address) {
uint256 rank = _heap.ranks[_id];
if (rank < _heap.accounts.length) return getAccount(_heap, rank + 1).id;
else return address(0);
if (rank == 0 || rank >= _heap.accounts.length) return address(0);

return getAccount(_heap, rank + 1).id;
}
}
5 changes: 5 additions & 0 deletions test-foundry/TestHeapOrdering.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,9 @@ contract TestHeapOrdering is DSTest {
hevm.expectRevert("SafeCast: value doesn't fit in 96 bits");
update(accounts[0], uint256(type(uint128).max), 0);
}

function testGetNextUnknown() public {
update(accounts[0], 0, 1);
assertEq(heap.getNext(address(0xdEaD)), ADDR_ZERO);
}
}

0 comments on commit 1702aac

Please sign in to comment.