ghash: Handle hash tables with millions of entries

Multiplying a guint value with BIG_ENTRY_SIZE (8) can overflow the guint
data type if size reaches 2^29. Use the correct size_t type for 64 bit
systems to support such allocations.

A 32 bit system should fail its reallocation way earlier before reaching
such a large "size", i.e. item count, especially when reallocating.
Also, it would multiply with 4.

Closes #3724
This commit is contained in:
Tobias Stoeckmann
2025-08-20 20:09:31 +02:00
parent 08872dcd47
commit 4bc794e42a

View File

@@ -323,7 +323,7 @@ g_hash_table_set_shift_from_size (GHashTable *hash_table, gint size)
}
static inline gpointer
g_hash_table_realloc_key_or_value_array (gpointer a, guint size, G_GNUC_UNUSED gboolean is_big)
g_hash_table_realloc_key_or_value_array (gpointer a, size_t size, G_GNUC_UNUSED gboolean is_big)
{
#ifdef USE_SMALL_ARRAYS
return g_realloc (a, size * (is_big ? BIG_ENTRY_SIZE : SMALL_ENTRY_SIZE));