From 47450425fd4221f1979eee95afda4801e389f3fc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 2 Oct 2024 10:19:40 -0700 Subject: [PATCH] Allow iterating just the keys or values in a hashtable --- src/SDL_hashtable.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/SDL_hashtable.c b/src/SDL_hashtable.c index f2b80c4cbb..52c8d7b096 100644 --- a/src/SDL_hashtable.c +++ b/src/SDL_hashtable.c @@ -18,7 +18,6 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - #include "SDL_internal.h" #include "SDL_hashtable.h" @@ -429,13 +428,21 @@ bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, const v HT_ASSERT(item <= end); if (item == end) { - *_key = NULL; - *_value = NULL; + if (_key) { + *_key = NULL; + } + if (_value) { + *_value = NULL; + } return false; } - *_key = item->key; - *_value = item->value; + if (_key) { + *_key = item->key; + } + if (_value) { + *_value = item->value; + } *iter = item; return true;