[glib/glib-2-60: 1/6] ghash: fix bug introduced by valgrind fix
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-60: 1/6] ghash: fix bug introduced by valgrind fix
- Date: Tue, 21 May 2019 10:29:56 +0000 (UTC)
commit 64f76bb1734c85986284b7f01eea76d9e1f1fdbf
Author: Allison Karlitskaya <allison karlitskaya redhat com>
Date: Wed May 15 16:17:04 2019 +0200
ghash: fix bug introduced by valgrind fix
g_hash_table_new_full() had an invocation of
g_hash_table_realloc_key_or_value_array() with the @is_big argument
incorrectly hardcoded to FALSE, even though later in the function the
values of have_big_keys and have_big_values would be set conditionally.
This never caused problems before because on 64bit platforms, this would
result in the allocation of a guint-sized array (which would be fine, as
have_big_keys and have_big_values would always start out as false) and
on 32bit platforms, this function ignored the value and always allocated
a gpointer-sized array.
Since merge request GNOME/glib!845 we have the possibility for
have_big_keys and have_big_values to start out as TRUE on 64bit
platforms. We need to make sure we pass the argument through correctly.
glib/ghash.c | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index c58e8c585..71b9fd862 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -1017,22 +1017,6 @@ g_hash_table_new_full (GHashFunc hash_func,
GHashTable *hash_table;
gboolean small;
- hash_table = g_slice_new (GHashTable);
- g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
- g_atomic_ref_count_init (&hash_table->ref_count);
- hash_table->nnodes = 0;
- hash_table->noccupied = 0;
- hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
- hash_table->key_equal_func = key_equal_func;
-#ifndef G_DISABLE_ASSERT
- hash_table->version = 0;
-#endif
- hash_table->key_destroy_func = key_destroy_func;
- hash_table->value_destroy_func = value_destroy_func;
- hash_table->keys = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, FALSE);
- hash_table->values = hash_table->keys;
- hash_table->hashes = g_new0 (guint, hash_table->size);
-
/* We want to use small arrays only if:
* - we are running on a system where that makes sense (64 bit); and
* - we are not running under valgrind.
@@ -1048,8 +1032,23 @@ g_hash_table_new_full (GHashFunc hash_func,
# endif
#endif
- hash_table->have_big_keys = !small;
- hash_table->have_big_values = !small;
+ hash_table = g_slice_new (GHashTable);
+ g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
+ g_atomic_ref_count_init (&hash_table->ref_count);
+ hash_table->nnodes = 0;
+ hash_table->noccupied = 0;
+ hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
+ hash_table->key_equal_func = key_equal_func;
+#ifndef G_DISABLE_ASSERT
+ hash_table->version = 0;
+#endif
+ hash_table->key_destroy_func = key_destroy_func;
+ hash_table->value_destroy_func = value_destroy_func;
+ hash_table->have_big_keys = !small;
+ hash_table->have_big_values = !small;
+ hash_table->keys = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size,
hash_table->have_big_keys);
+ hash_table->values = hash_table->keys;
+ hash_table->hashes = g_new0 (guint, hash_table->size);
return hash_table;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]