From: Amos Jeffries Date: Sat, 22 Nov 2014 06:10:20 +0000 (-0800) Subject: Revert splay-specific pieces of rev.13720 X-Git-Tag: merge-candidate-3-v1~472 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0673a6f44ca99c57c41e5b78e818f12cbed231f9;p=thirdparty%2Fsquid.git Revert splay-specific pieces of rev.13720 As suspected several important pieces of code depend on the SplayNode this pointer being NUL at times. --- diff --git a/include/splay.h b/include/splay.h index 9b83b6d7f7..eae7380d33 100644 --- a/include/splay.h +++ b/include/splay.h @@ -32,7 +32,7 @@ public: mutable SplayNode *right; void destroy(SPLAYFREE *); void walk(SPLAYWALKEE *, void *callerState); - bool empty() const {return false;} + bool empty() const { return this == NULL; } SplayNode const * start() const; SplayNode const * finish() const; @@ -110,6 +110,9 @@ template void SplayNode::walk(SPLAYWALKEE * walkee, void *state) { + if (this == NULL) + return; + if (left) left->walk(walkee, state); @@ -123,7 +126,7 @@ template SplayNode const * SplayNode::start() const { - if (left) + if (this && left) return left->start(); return this; @@ -133,7 +136,7 @@ template SplayNode const * SplayNode::finish() const { - if (right) + if (this && right) return right->finish(); return this; @@ -143,6 +146,9 @@ template void SplayNode::destroy(SPLAYFREE * free_func) { + if (!this) + return; + if (left) left->destroy(free_func); @@ -158,6 +164,9 @@ template SplayNode * SplayNode::remove(Value const dataToRemove, SPLAYCMP * compare) { + if (this == NULL) + return NULL; + SplayNode *result = splay(dataToRemove, compare); if (splayLastResult == 0) { /* found it */ @@ -186,6 +195,12 @@ SplayNode::insert(Value dataToInsert, SPLAYCMP * compare) /* create node to insert */ SplayNode *newNode = new SplayNode(dataToInsert); + if (this == NULL) { + splayLastResult = -1; + newNode->left = newNode->right = NULL; + return newNode; + } + SplayNode *newTop = splay(dataToInsert, compare); if (splayLastResult < 0) { @@ -210,6 +225,12 @@ template SplayNode * SplayNode::splay(FindValue const &dataToFind, int( * compare)(FindValue const &a, Value const &b)) const { + if (this == NULL) { + /* can't have compared successfully :} */ + splayLastResult = -1; + return NULL; + } + Value temp = Value(); SplayNode N(temp); SplayNode *l;