]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Restored splay NULL checks. Things break without them
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 31 Dec 2014 08:45:23 +0000 (09:45 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 31 Dec 2014 08:45:23 +0000 (09:45 +0100)
include/splay.h

index c37b1a60f353afde1a5b1a9a1410bf3ff9ddcad7..4be51842f5c4d6875a7c7b4100d6a919eca52b95 100644 (file)
@@ -116,6 +116,9 @@ template<class V>
 void
 SplayNode<V>::walk(SPLAYWALKEE * walkee, void *state)
 {
+    if (this == NULL)
+        return;
+
     if (left)
         left->walk(walkee, state);
 
@@ -129,7 +132,7 @@ template<class V>
 SplayNode<V> const *
 SplayNode<V>::start() const
 {
-    if (left)
+    if (this && left)
         return left->start();
 
     return this;
@@ -139,7 +142,7 @@ template<class V>
 SplayNode<V> const *
 SplayNode<V>::finish() const
 {
-    if (right)
+    if (this && right)
         return right->finish();
 
     return this;
@@ -149,6 +152,9 @@ template<class V>
 void
 SplayNode<V>::destroy(SPLAYFREE * free_func)
 {
+    if (!this)
+        return;
+
     if (left)
         left->destroy(free_func);
 
@@ -164,6 +170,9 @@ template<class V>
 SplayNode<V> *
 SplayNode<V>::remove(Value const dataToRemove, SPLAYCMP * compare)
 {
+    if (this == NULL)
+        return NULL;
+
     SplayNode<V> *result = splay(dataToRemove, compare);
 
     if (splayLastResult == 0) { /* found it */
@@ -192,6 +201,12 @@ SplayNode<V>::insert(Value dataToInsert, SPLAYCMP * compare)
     /* create node to insert */
     SplayNode<V> *newNode = new SplayNode<V>(dataToInsert);
 
+    if (this == NULL) {
+        splayLastResult = -1;
+        newNode->left = newNode->right = NULL;
+        return newNode;
+    }
+
     SplayNode<V> *newTop = splay(dataToInsert, compare);
 
     if (splayLastResult < 0) {
@@ -216,6 +231,12 @@ template<class FindValue>
 SplayNode<V> *
 SplayNode<V>::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<V> N(temp);
     SplayNode<V> *l;