From a60f0eefb8e5c705a0bc3c70c44ebddb6ce4f545 Mon Sep 17 00:00:00 2001 From: Thomas Arp <357770+welcor@users.noreply.github.com> Date: Sat, 7 Mar 2020 23:22:01 +0100 Subject: [PATCH] Minor bugfix in code that should be unreachable. We already log that we update, but no update was taking place. --- src/dg_scripts.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dg_scripts.c b/src/dg_scripts.c index 709f5f5..2cf4539 100644 --- a/src/dg_scripts.c +++ b/src/dg_scripts.c @@ -2994,10 +2994,15 @@ void init_lookup_table(void) } } -static struct lookup_table_t *find_element_by_uid_in_lookup_table(long uid) +static struct lookup_table_t *get_bucket_head(long uid) { int bucket = (int) (uid & (BUCKET_COUNT - 1)); - struct lookup_table_t *lt = &lookup_table[bucket]; + return &lookup_table[bucket]; +} + +static struct lookup_table_t *find_element_by_uid_in_lookup_table(long uid) +{ + struct lookup_table_t *lt = get_bucket_head(uid); for (;lt && lt->uid != uid ; lt = lt->next) ; return lt; @@ -3034,8 +3039,7 @@ int has_obj_by_uid_in_lookup_table(long uid) void add_to_lookup_table(long uid, void *c) { - int bucket = (int) (uid & (BUCKET_COUNT - 1)); - struct lookup_table_t *lt = &lookup_table[bucket]; + struct lookup_table_t *lt = get_bucket_head(uid); if (lt && lt->uid == uid) { log("add_to_lookup updating existing value for uid=%ld (%p -> %p)", uid, lt->c, c); @@ -3046,6 +3050,7 @@ void add_to_lookup_table(long uid, void *c) for (;lt && lt->next; lt = lt->next) if (lt->next->uid == uid) { log("add_to_lookup updating existing value for uid=%ld (%p -> %p)", uid, lt->next->c, c); + lt->next->c = c; return; }