From 0cd679077f2e80f4db85dcd87bd8a5087d060cdb Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Mon, 25 Jul 2022 18:29:21 +0200 Subject: [PATCH] fix: one litteral value left, account memory in loop --- contracts/HeapOrdering.sol | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/contracts/HeapOrdering.sol b/contracts/HeapOrdering.sol index 26d4ad89..7418c0da 100644 --- a/contracts/HeapOrdering.sol +++ b/contracts/HeapOrdering.sol @@ -153,17 +153,15 @@ library HeapOrdering { uint256 size = _heap.size; Account memory accountToShift = getAccount(_heap, _rank); uint256 valueToShift = accountToShift.value; - Account memory childToSwap; - Account memory rightChild; uint256 childRank = _rank << 1; // At this point, childRank (resp. childRank+1) is the rank of the left (resp. right) child. while (childRank <= size) { - childToSwap = getAccount(_heap, childRank); + Account memory childToSwap = getAccount(_heap, childRank); // Find the child with largest value. if (childRank < size) { - rightChild = getAccount(_heap, childRank + 1); + Account memory rightChild = getAccount(_heap, childRank + 1); if (rightChild.value > childToSwap.value) { unchecked { ++childRank; // This cannot overflow because childRank < size. @@ -299,7 +297,7 @@ library HeapOrdering { /// @param _heap The heap to get the head. /// @return The address of the head. function getHead(HeapArray storage _heap) internal view returns (address) { - if (_heap.accounts.length > 0) return getAccount(_heap, 1).id; + if (_heap.accounts.length > 0) return getAccount(_heap, ROOT).id; else return address(0); }