@@ -6,21 +6,25 @@ library BytesLib {
66 * ERRORS *
77 **************************************/
88 error OutOfBounds ();
9- error InvalidBytes ();
10- error InvalidStart ();
119
1210 /**************************************
1311 * FUNCTIONS *
1412 **************************************/
1513
14+ // The following 4 functions are copied from solidity-bytes-utils library
15+ // https://github.com/GNSPS/solidity-bytes-utils/blob/fc502455bb2a7e26a743378df042612dd50d1eb9/contracts/BytesLib.sol#L323C5-L398C6
16+ // Code was copied, and slightly modified to use revert instead of require
17+
1618 /**
1719 * @notice Reads a uint16 from a bytes array at a given start index
1820 * @param _bytes The bytes array to convert
1921 * @param _start The start index of the uint16
2022 * @return result The uint16 result
2123 */
2224 function toUint16 (bytes memory _bytes , uint256 _start ) internal pure returns (uint16 result ) {
23- require (_bytes.length >= _start + 2 , "toUint16_outOfBounds " );
25+ if (_bytes.length < _start + 2 ) {
26+ revert OutOfBounds ();
27+ }
2428
2529 // solhint-disable-next-line no-inline-assembly
2630 assembly {
@@ -81,6 +85,8 @@ library BytesLib {
8185
8286 /**
8387 * @notice Reads a bytes array from a bytes array at a given start index and length
88+ * Source: https://github.com/Vectorized/solady/blob/21202175063a0010826bf42697b5aa2ff0c27f9f/src/utils/LibBytes.sol#L369C5-L396C6
89+ * Code was copied, was not modified
8490 * @param _bytes The bytes array to convert
8591 * @param _start The start index of the bytes array
8692 * @param _end The end index of the bytes array
0 commit comments