Skip to content

Commit

Permalink
Fixed and cleaned up logic for DieFast.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Nov 9, 2019
1 parent 008ac97 commit 03b24ea
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions src/include/randomminiheap-core.h
Expand Up @@ -120,15 +120,10 @@ class RandomMiniHeapCore : public RandomMiniHeapBase {
if (DieFastOn) {
// Check to see if this object was overflowed.
if (DieFast::checkNot (ptr, ObjectSize, _freedValue)) {
auto * l = (size_t *) ptr;
int i;
for (i = 0; i < (int) (ObjectSize / sizeof(size_t)); i++) {
if (l[i] != _freedValue) {
break;
}
}
reportOverflowError(ptr, i * sizeof(size_t));
reportOverflowError(ptr, overflowIndex(ptr));
}
// Check if the object to the left or to the right are intact (if they are free).
checkOverflowError(index);
}

// Make sure the returned object is the right size.
Expand Down Expand Up @@ -162,6 +157,12 @@ class RandomMiniHeapCore : public RandomMiniHeapBase {
reportDoubleFreeError(ptr);
didFree = false;
}

if (DieFastOn) {
// Check if the object to the left or to the right are intact (if they are free).
checkOverflowError(index);
}

return didFree;
}

Expand Down Expand Up @@ -191,33 +192,47 @@ class RandomMiniHeapCore : public RandomMiniHeapBase {
virtual bool inBounds (void * ptr) const = 0;


#if 0
private:

unsigned int overflowIndex(void * ptr) {
auto * l = (size_t *) ptr;
unsigned int i;
for (i = 0; i < (int) (ObjectSize / sizeof(size_t)); i++) {
if (l[i] != _freedValue) {
break;
}
}
return i * sizeof(size_t);
}

#if 1
/// @brief Checks for overflows.
void checkOverflowError (void * ptr, unsigned int index)
void checkOverflowError (unsigned int index)
{
ptr = ptr;
index = index;
if (!DieHarderOn) {
auto leftIndex = (index - 1) % NObjects;
auto rightIndex = (index + 1) % NObjects;

if (DieHarderOn) {
// Check predecessor.
if (!_miniHeapBitmap.isSet (index - 1)) {
void * p = (void *) (((ObjectStruct *) ptr) - 1);
if (!_miniHeapBitmap.isSet (leftIndex)) {
void * p = getObject(leftIndex);
if (DieFast::checkNot (p, ObjectSize, _freedValue)) {
reportOverflowError(ptr);
reportOverflowError(p, overflowIndex(p));
}
}
// Check successor.
if ((index < (NObjects - 1)) &&
(!_miniHeapBitmap.isSet (index + 1))) {
void * p = (void *) (((ObjectStruct *) ptr) + 1);
if (!_miniHeapBitmap.isSet (rightIndex)) {
void * p = getObject(rightIndex);
if (DieFast::checkNot (p, ObjectSize, _freedValue)) {
reportOverflowError(ptr);
reportOverflowError(p, overflowIndex(p));
}
}
}
}
#endif


protected:

/// @return true iff heap is currently active.
inline bool isActivated() const {
return _isHeapActivated;
Expand Down

0 comments on commit 03b24ea

Please sign in to comment.