Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
3dadd400
Unverified
Commit
3dadd400
authored
Jul 30, 2021
by
Anton Bukov
Committed by
GitHub
Jul 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid safe math in BitMap (#2797)
parent
566a7742
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
BitMaps.sol
contracts/utils/structs/BitMaps.sol
+6
-6
No files found.
contracts/utils/structs/BitMaps.sol
View file @
3dadd400
...
...
@@ -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;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment