From 1272b289e643b8519307d43b724a1bf0ca4ae228 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sun, 6 Aug 2017 18:37:20 +0100 Subject: [PATCH] librb: dictionary_add mishandles replacing elements This can only happen with soft asserts otherwise it will crash instead. Nothing currently uses the return value of rb_dictionary_add. --- librb/src/dictionary.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/librb/src/dictionary.c b/librb/src/dictionary.c index 124edbbe..8aa54fcd 100644 --- a/librb/src/dictionary.c +++ b/librb/src/dictionary.c @@ -272,7 +272,7 @@ rb_dictionary_retune(rb_dictionary *dict, const void *key) * Side Effects: * - a node is linked to the dictionary tree */ -static void +static rb_dictionary_element * rb_dictionary_link(rb_dictionary *dict, rb_dictionary_element *delem) { @@ -334,8 +334,11 @@ rb_dictionary_link(rb_dictionary *dict, dict->count--; rb_free(delem); + delem = dict->root; } } + + return delem; } /* @@ -686,9 +689,7 @@ rb_dictionary_element *rb_dictionary_add(rb_dictionary *dict, const void *key, v delem->key = key; delem->data = data; - rb_dictionary_link(dict, delem); - - return delem; + return rb_dictionary_link(dict, delem); } /*