From: Francesco Chemolli Date: Wed, 31 Dec 2014 08:45:23 +0000 (+0100) Subject: Restored splay NULL checks. Things break without them X-Git-Tag: merge-candidate-3-v1~384^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c9ed72a0233a2c972066ffbe6c19256b47b6b9a;p=thirdparty%2Fsquid.git Restored splay NULL checks. Things break without them --- diff --git a/include/splay.h b/include/splay.h index c37b1a60f3..4be51842f5 100644 --- a/include/splay.h +++ b/include/splay.h @@ -116,6 +116,9 @@ template void SplayNode::walk(SPLAYWALKEE * walkee, void *state) { + if (this == NULL) + return; + if (left) left->walk(walkee, state); @@ -129,7 +132,7 @@ template SplayNode const * SplayNode::start() const { - if (left) + if (this && left) return left->start(); return this; @@ -139,7 +142,7 @@ template SplayNode const * SplayNode::finish() const { - if (right) + if (this && right) return right->finish(); return this; @@ -149,6 +152,9 @@ template void SplayNode::destroy(SPLAYFREE * free_func) { + if (!this) + return; + if (left) left->destroy(free_func); @@ -164,6 +170,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 */ @@ -192,6 +201,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) { @@ -216,6 +231,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;