diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2012-02-09 17:59:55 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2012-02-10 10:03:38 +0100 |
commit | 6d3b31a533d74b727bca5ac720a81eacb8aee31e (patch) | |
tree | ddb9bda07a42302b18638a3f1d7a3c066353d90b | |
parent | b17b135d9f4fa5652d64decf1d1cd0cad7de21f0 (diff) | |
download | glib-6d3b31a533d74b727bca5ac720a81eacb8aee31e.tar.gz |
Fix g_hash_table_foreach crash with NULL hash table
When G_DISABLE_ASSERT is not defined, g_hash_table_foreach and
g_hash_table_find dereferences the hash table argument before
checking if it's NULL. This causes a crash when one of this function
is mistakenly called with a NULL argument instead of returning
with a warning through g_return_if_fail.
-rw-r--r-- | glib/ghash.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/glib/ghash.c b/glib/ghash.c index b058d171d..e204a40ad 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -1504,12 +1504,16 @@ g_hash_table_foreach (GHashTable *hash_table, { gint i; #ifndef G_DISABLE_ASSERT - gint version = hash_table->version; + gint version; #endif g_return_if_fail (hash_table != NULL); g_return_if_fail (func != NULL); +#ifndef G_DISABLE_ASSERT + version = hash_table->version; +#endif + for (i = 0; i < hash_table->size; i++) { guint node_hash = hash_table->hashes[i]; @@ -1558,13 +1562,17 @@ g_hash_table_find (GHashTable *hash_table, { gint i; #ifndef G_DISABLE_ASSERT - gint version = hash_table->version; + gint version; #endif gboolean match; g_return_val_if_fail (hash_table != NULL, NULL); g_return_val_if_fail (predicate != NULL, NULL); +#ifndef G_DISABLE_ASSERT + version = hash_table->version; +#endif + match = FALSE; for (i = 0; i < hash_table->size; i++) |