Merge pull request #2412 from atn34/atn34/fix-skiplist-ub
Fix ub in MiniConflictSet (Skiplist.cpp)
This commit is contained in:
commit
d94a1dfef2
|
@ -1035,8 +1035,8 @@ class MiniConflictSet : NonCopyable {
|
|||
std::vector<wordType> andValues;
|
||||
MiniConflictSet2 debug; // SOMEDAY: Test on big ranges, eliminate this
|
||||
|
||||
uint64_t bitMask(unsigned int bit){ // computes results for bit%word
|
||||
return (((wordType)1) << ( bit & bucketMask )); // '&' unnecesary?
|
||||
wordType bitMask(unsigned int bit) { // computes results for bit%word
|
||||
return (((wordType)1) << (bit & bucketMask));
|
||||
}
|
||||
void setNthBit(std::vector<wordType>& v, const unsigned int bit){
|
||||
v[bit>>bucketShift] |= bitMask(bit);
|
||||
|
@ -1052,11 +1052,11 @@ class MiniConflictSet : NonCopyable {
|
|||
}
|
||||
wordType highBits(int b){ // bits (b&bucketMask) and higher are 1
|
||||
#pragma warning(disable: 4146)
|
||||
return -(wordType(1) << b);
|
||||
return -bitMask(b);
|
||||
#pragma warning(default: 4146)
|
||||
}
|
||||
wordType lowBits(int b){ // bits lower than b are 1
|
||||
return (wordType(1)<<b)-1;
|
||||
wordType lowBits(int b) { // bits lower than (b&bucketMask) are 1
|
||||
return bitMask(b) - 1;
|
||||
}
|
||||
wordType lowBits2(int b) {
|
||||
return (b&bucketMask) ? lowBits(b) : -1;
|
||||
|
@ -1092,6 +1092,15 @@ class MiniConflictSet : NonCopyable {
|
|||
}
|
||||
}
|
||||
|
||||
bool orImpl(int begin, int end) {
|
||||
if (begin == end) return false;
|
||||
int beginWord = begin >> bucketShift;
|
||||
int lastWord = ((end + bucketMask) >> bucketShift) - 1;
|
||||
|
||||
return orBits(orValues, beginWord + 1, lastWord, true) || getNthBit(andValues, beginWord) ||
|
||||
getNthBit(andValues, lastWord) || orBits(values, begin, end, false);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit MiniConflictSet( int size ) : debug(size) {
|
||||
static_assert((1<<bucketShift) == sizeof(wordType)*8, "BucketShift incorrect");
|
||||
|
@ -1119,16 +1128,6 @@ public:
|
|||
ASSERT( a == b );
|
||||
return b;
|
||||
}
|
||||
|
||||
bool orImpl( int begin, int end ) {
|
||||
if (begin == end) return false;
|
||||
int beginWord = begin>>bucketShift;
|
||||
int lastWord = ((end+bucketMask) >> bucketShift) - 1;
|
||||
|
||||
return orBits( orValues, beginWord+1, lastWord, true ) ||
|
||||
getNthBit( andValues, beginWord ) || getNthBit( andValues, lastWord ) ||
|
||||
orBits( values, begin, end, false );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue