From cee644a6a7eace21e0ead3f5f2774408baded9d7 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Thu, 28 Nov 2024 16:14:47 +0000 Subject: [PATCH] fix sonarqube issues --- src/pr_tree.c | 4 ++-- src/skiplist.c | 2 +- src/tree_common.c | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pr_tree.c b/src/pr_tree.c index dac1ed4..4fd3bcb 100644 --- a/src/pr_tree.c +++ b/src/pr_tree.c @@ -466,10 +466,10 @@ node_verify(const pr_tree* tree, const pr_node* parent, const pr_node* node) unsigned lweight = WEIGHT(l); unsigned rweight = WEIGHT(r); VERIFY(node->weight == lweight + rweight); - if (rweight > lweight) { + if (r && rweight > lweight) { VERIFY(WEIGHT(r->rlink) <= lweight); VERIFY(WEIGHT(r->llink) <= lweight); - } else if (lweight > rweight) { + } else if (l && lweight > rweight) { VERIFY(WEIGHT(l->llink) <= rweight); VERIFY(WEIGHT(l->rlink) <= rweight); } diff --git a/src/skiplist.c b/src/skiplist.c index fed1d81..6b91cea 100644 --- a/src/skiplist.c +++ b/src/skiplist.c @@ -169,7 +169,7 @@ node_insert(skiplist* list, skip_node* x, skip_node** update) } x->prev = (update[0] == list->head) ? NULL : update[0]; - if (update[0]->link[0]) + if (update[0]->link && update[0]->link[0]) update[0]->link[0]->prev = x; for (unsigned k = 0; k < nlinks; k++) { ASSERT(update[k]->link_count > k); diff --git a/src/tree_common.c b/src/tree_common.c index 5441a00..0c81629 100644 --- a/src/tree_common.c +++ b/src/tree_common.c @@ -401,14 +401,22 @@ bool tree_iterator_next(void* Iterator) { tree_iterator* iterator = Iterator; - return (iterator->node != NULL) && (iterator->node = tree_node_next(iterator->node)) != NULL; + if(iterator->node) { + iterator->node = tree_node_next(iterator->node); + if(iterator->node) return true; + } + return false; } bool tree_iterator_prev(void* Iterator) { tree_iterator* iterator = Iterator; - return (iterator->node != NULL) && (iterator->node = tree_node_prev(iterator->node)) != NULL; + if(iterator->node) { + iterator->node = tree_node_prev(iterator->node); + if(iterator->node) return true; + } + return false; } bool