Unverified Commit 3dadd400 by Anton Bukov Committed by GitHub

Avoid safe math in BitMap (#2797)

parent 566a7742
......@@ -14,8 +14,8 @@ library BitMaps {
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index / 256;
uint256 mask = 1 << (index % 256);
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
......@@ -38,8 +38,8 @@ library BitMaps {
* @dev Sets the bit at `index`.
*/
function set(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index / 256;
uint256 mask = 1 << (index % 256);
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] |= mask;
}
......@@ -47,8 +47,8 @@ library BitMaps {
* @dev Unsets the bit at `index`.
*/
function unset(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index / 256;
uint256 mask = 1 << (index % 256);
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] &= ~mask;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment