@@ -4,6 +4,8 @@ pragma solidity ^0.8.29;
44library AssociatedArrayLib {
55 using AssociatedArrayLib for * ;
66
7+ uint256 constant MAX_ARRAY_LENGTH = 127 ;
8+
79 struct Array {
810 uint256 _spacer;
911 }
@@ -21,9 +23,12 @@ library AssociatedArrayLib {
2123 }
2224
2325 error AssociatedArray_OutOfBounds (uint256 index );
26+ error AssociatedArray_LengthExceeded (uint256 length );
2427
2528 function add (Bytes32Array storage s , address account , bytes32 value ) internal {
2629 if (! _contains (s._inner, account, value)) {
30+ uint256 currentLength = _length (s._inner, account);
31+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
2732 _push (s._inner, account, value);
2833 }
2934 }
@@ -33,6 +38,8 @@ library AssociatedArrayLib {
3338 }
3439
3540 function push (Bytes32Array storage s , address account , bytes32 value ) internal {
41+ uint256 currentLength = _length (s._inner, account);
42+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
3643 _push (s._inner, account, value);
3744 }
3845
@@ -46,6 +53,8 @@ library AssociatedArrayLib {
4653
4754 function add (UintArray storage s , address account , uint256 value ) internal {
4855 if (! _contains (s._inner, account, bytes32 (value))) {
56+ uint256 currentLength = _length (s._inner, account);
57+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
4958 _push (s._inner, account, bytes32 (value));
5059 }
5160 }
@@ -55,6 +64,8 @@ library AssociatedArrayLib {
5564 }
5665
5766 function push (UintArray storage s , address account , uint256 value ) internal {
67+ uint256 currentLength = _length (s._inner, account);
68+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
5869 _push (s._inner, account, bytes32 (value));
5970 }
6071
@@ -68,6 +79,8 @@ library AssociatedArrayLib {
6879
6980 function add (AddressArray storage s , address account , address value ) internal {
7081 if (! _contains (s._inner, account, bytes32 (uint256 (uint160 (value))))) {
82+ uint256 currentLength = _length (s._inner, account);
83+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
7184 _push (s._inner, account, bytes32 (uint256 (uint160 (value))));
7285 }
7386 }
@@ -77,6 +90,8 @@ library AssociatedArrayLib {
7790 }
7891
7992 function push (AddressArray storage s , address account , address value ) internal {
93+ uint256 currentLength = _length (s._inner, account);
94+ if (currentLength >= MAX_ARRAY_LENGTH) revert AssociatedArray_LengthExceeded (currentLength);
8095 _push (s._inner, account, bytes32 (uint256 (uint160 (value))));
8196 }
8297
0 commit comments