Disallow empty CircularBuffer setup (#5214)

This commit is contained in:
Ernesto García
2024-09-19 11:20:04 -06:00
committed by GitHub
parent b1f6bbe69f
commit 530179a71f
2 changed files with 10 additions and 0 deletions

View File

@ -36,6 +36,11 @@ import {Panic} from "../Panic.sol";
* ```
*/
library CircularBuffer {
/**
* @dev Error emitted when trying to setup a buffer with a size of 0.
*/
error InvalidBufferSize();
/**
* @dev Counts the number of items that have been pushed to the buffer. The residuo modulo _data.length indicates
* where the next value should be stored.
@ -61,6 +66,7 @@ library CircularBuffer {
* Consider a large buffer size may render the function unusable.
*/
function setup(Bytes32CircularBuffer storage self, uint256 size) internal {
if (size == 0) revert InvalidBufferSize();
clear(self);
Arrays.unsafeSetLength(self._data, size);
}