Skip to content
Permalink
Browse files

Fixed and cleaned up logic for DieFast.

  • Loading branch information
emeryberger committed Nov 9, 2019
1 parent 008ac97 commit 03b24ea88125fdb2ac6d1fd9620125fe4909816c
Showing with 36 additions and 21 deletions.
  1. +36 −21 src/include/randomminiheap-core.h
@@ -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.
@@ -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;
}

@@ -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;

0 comments on commit 03b24ea

Please sign in to comment.
You can’t perform that action at this time.