Skip to content

Commit 0654ae4

Browse files
authored
Update StdMath.sol
1 parent 0768d9c commit 0654ae4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/StdMath.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ library stdMath {
2929
}
3030

3131
function percentDelta(uint256 a, uint256 b) internal pure returns (uint256) {
32+
// Prevent division by zero
33+
require(b != 0, "stdMath: percentDelta divisor is zero");
3234
uint256 absDelta = delta(a, b);
3335

3436
return absDelta * 1e18 / b;
@@ -37,6 +39,8 @@ library stdMath {
3739
function percentDelta(int256 a, int256 b) internal pure returns (uint256) {
3840
uint256 absDelta = delta(a, b);
3941
uint256 absB = abs(b);
42+
// Prevent division by zero
43+
require(absB != 0, "stdMath: percentDelta divisor is zero");
4044

4145
return absDelta * 1e18 / absB;
4246
}

0 commit comments

Comments
 (0)