[glib/glib-2-30] Fix g_hash_table_foreach crash with NULL hash table
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-30] Fix g_hash_table_foreach crash with NULL hash table
- Date: Sun, 11 Mar 2012 22:23:24 +0000 (UTC)
commit 125ceb1d447b75a46edcfb056dab2fd79cab273a
Author: Christophe Fergeau <cfergeau redhat com>
Date: Thu Feb 9 17:59:55 2012 +0100
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.
glib/ghash.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index 5eb093f..be9fd68 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -1429,12 +1429,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];
@@ -1483,13 +1487,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++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]