diff --git a/contracts/utils/Checkpoints.sol b/contracts/utils/Checkpoints.sol index 793ea3bd1..1692a6d15 100644 --- a/contracts/utils/Checkpoints.sol +++ b/contracts/utils/Checkpoints.sol @@ -237,7 +237,7 @@ library Checkpoints { offset <<= 1; } - uint256 low = offset < length ? length - offset : 0; + uint256 low = 0 < offset && offset < length ? length - offset : 0; uint256 high = length - (offset >> 1); uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high); @@ -392,7 +392,7 @@ library Checkpoints { offset <<= 1; } - uint256 low = offset < length ? length - offset : 0; + uint256 low = 0 < offset && offset < length ? length - offset : 0; uint256 high = length - (offset >> 1); uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high); diff --git a/scripts/generate/templates/Checkpoints.js b/scripts/generate/templates/Checkpoints.js index e368299f3..b6a9ce04c 100644 --- a/scripts/generate/templates/Checkpoints.js +++ b/scripts/generate/templates/Checkpoints.js @@ -83,7 +83,7 @@ function upperLookupRecent(${opts.historyTypeName} storage self, ${opts.keyTypeN offset <<= 1; } - uint256 low = offset < length ? length - offset : 0; + uint256 low = 0 < offset && offset < length ? length - offset : 0; uint256 high = length - (offset >> 1); uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, low, high);