From c2888a2b9f644c9da6fec019db4c44fe8cb6e3be Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 23 Aug 2018 11:35:43 -0400 Subject: [PATCH] Fix: bt_g_hash_table_contains(): handle `NULL`/0 values Issue ===== g_hash_table_lookup() returns `NULL` if the key is not found, but also when the value is actually `NULL` (or 0). Therefore bt_g_hash_table_contains() returns false when there's actually a `NULL`/0 value for the given key. Solution ======== Use g_hash_table_lookup_extended() which truly returns whether or not the given key was found, and discard the returned value. Known drawbacks =============== None. Signed-off-by: Philippe Proulx --- include/babeltrace/compat/glib-internal.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/babeltrace/compat/glib-internal.h b/include/babeltrace/compat/glib-internal.h index dd03b19c..fd253559 100644 --- a/include/babeltrace/compat/glib-internal.h +++ b/include/babeltrace/compat/glib-internal.h @@ -40,14 +40,11 @@ bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) static inline gboolean bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) { - const char *value; + gpointer orig_key; + gpointer value; - value = g_hash_table_lookup(hash_table, key); - if (value == NULL) { - return FALSE; - } - - return TRUE; + return g_hash_table_lookup_extended(hash_table, key, &orig_key, + &value); } #endif -- 2.34.1