[glib: 1/3] ghash: Clear out arguments to NULL in g_hash_table_lookup_extended()



commit 8dc8b33dfa7fc42ac0dfa382f35ca90043784985
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Aug 31 12:45:29 2018 +0100

    ghash: Clear out arguments to NULL in g_hash_table_lookup_extended()
    
    If the given key is not found, clear the orig_key and value arguments to
    NULL as well as returning FALSE. Then the caller can unconditionally
    check them.
    
    This makes the behaviour of g_hash_table_lookup_extended() consistent
    with g_hash_table_steal_extended().
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/ghash.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index 433004cf8..18c7185ef 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -1190,7 +1190,14 @@ g_hash_table_lookup_extended (GHashTable    *hash_table,
   node_index = g_hash_table_lookup_node (hash_table, lookup_key, &node_hash);
 
   if (!HASH_IS_REAL (hash_table->hashes[node_index]))
-    return FALSE;
+    {
+      if (orig_key != NULL)
+        *orig_key = NULL;
+      if (value != NULL)
+        *value = NULL;
+
+      return FALSE;
+    }
 
   if (orig_key)
     *orig_key = hash_table->keys[node_index];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]