From 6e0e50d52f6c2cd5f1686de23375f46847605ee7 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 27 Feb 2024 20:24:45 +0100 Subject: [PATCH] added checking pointers for hash table iterator --- src/libgame/hash.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libgame/hash.c b/src/libgame/hash.c index 4dd904c9..b3595ad4 100644 --- a/src/libgame/hash.c +++ b/src/libgame/hash.c @@ -423,18 +423,24 @@ hashtable_iterator(struct hashtable *h) /* key - return the key of the (key, value) pair at the current position */ void * -hashtable_iterator_key(struct hashtable_itr *i) +hashtable_iterator_key(struct hashtable_itr *itr) { - return i->e->k; + if (itr == NULL || itr->e == NULL) + return NULL; + + return itr->e->k; } /*****************************************************************************/ /* value - return the value of the (key, value) pair at the current position */ void * -hashtable_iterator_value(struct hashtable_itr *i) +hashtable_iterator_value(struct hashtable_itr *itr) { - return i->e->v; + if (itr == NULL || itr->e == NULL) + return NULL; + + return itr->e->v; } /*****************************************************************************/ -- 2.34.1