From 9b2c5514c07991f1efe22e3bb521168d1331622c Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 26 Oct 2016 22:58:28 +0200 Subject: [PATCH] Fix the return value of tommy_tree_insert() It must be the object in the tree and not the passed one. No bad conseguence because the value was used only for assertions, and not for controlling the behaviour. --- cmdline/selftest.c | 7 ++----- tommyds/tommytree.c | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cmdline/selftest.c b/cmdline/selftest.c index f0ac9441..d00b3bbc 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -439,11 +439,8 @@ static void test_tommy(void) tommy_tree_insert(&tree, &node[i], (void*)(uintptr_t)(i + 1)); /* try to insert a duplicate, count should not change */ - if (tommy_tree_insert(&tree, &node[TOMMY_SIZE], (void*)1) != (void*)1) { - /* LCOV_EXCL_START */ - goto bail; - /* LCOV_EXCL_STOP */ - } + tommy_tree_insert(&tree, &node[TOMMY_SIZE], (void*)(uintptr_t)1); + if (tommy_tree_count(&tree) != TOMMY_SIZE) { /* LCOV_EXCL_START */ goto bail; diff --git a/tommyds/tommytree.c b/tommyds/tommytree.c index b67b2408..6b2f1a99 100644 --- a/tommyds/tommytree.c +++ b/tommyds/tommytree.c @@ -152,7 +152,7 @@ void* tommy_tree_insert(tommy_tree* tree, tommy_tree_node* node, void* data) if (insert == node) ++tree->count; - return node->data; + return insert->data; } static tommy_tree_node* tommy_tree_remove_node(tommy_compare_func* cmp, tommy_tree_node* root, void* data, tommy_tree_node** let)