Skip to content

Commit df473af

Browse files
committed
use Math.saturatingAdd to more closelly match original syntax
1 parent cfbb2e6 commit df473af

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

contracts/utils/Bytes.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ library Bytes {
5757
*/
5858
function lastIndexOf(bytes memory buffer, bytes1 s, uint256 pos) internal pure returns (uint256) {
5959
unchecked {
60-
uint256 length = buffer.length;
61-
uint256 end = Math.ternary(pos == type(uint256).max, length, Math.min(pos + 1, length));
62-
for (uint256 i = end; i > 0; --i) {
60+
for (uint256 i = Math.min(Math.saturatingAdd(pos, 1), buffer.length); i > 0; --i) {
6361
if (bytes1(_unsafeReadBytesOffset(buffer, i - 1)) == s) {
6462
return i - 1;
6563
}

0 commit comments

Comments
 (0)