From e45bad430e8eefc90c9f0bf30442679d3f1aa160 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Fri, 2 Jan 2015 10:04:54 +0100 Subject: [PATCH] Added correct NULL check in Splay::find --- include/splay.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/splay.h b/include/splay.h index 1eea51480e..78093798bd 100644 --- a/include/splay.h +++ b/include/splay.h @@ -121,7 +121,7 @@ template SplayNode const * SplayNode::start() const { - if (this && left) + if (left) return left->start(); return this; @@ -131,7 +131,7 @@ template SplayNode const * SplayNode::finish() const { - if (this && right) + if (right) return right->finish(); return this; @@ -159,8 +159,7 @@ template SplayNode * SplayNode::remove(Value const dataToRemove, SPLAYCMP * compare) { - if (this == NULL) - return NULL; + assert(this != NULL); SplayNode *result = splay(dataToRemove, compare); @@ -190,11 +189,7 @@ 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; - } + assert(this != NULL); SplayNode *newTop = splay(dataToInsert, compare); @@ -220,11 +215,7 @@ 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; - } + assert(this != NULL); Value temp = Value(); SplayNode N(temp); @@ -311,6 +302,9 @@ template typename Splay::Value const * Splay::find (FindValue const &value, int( * compare)(FindValue const &a, Value const &b)) const { + if (head == NULL) + return NULL; + head = head->splay(value, compare); if (splayLastResult != 0) -- 2.47.3