ghash: Call g_error if hash table grows too large

Gracefully handle the case when too many items (billions) are added to a
hash table.
This commit is contained in:
Tobias Stoeckmann
2025-08-20 20:15:41 +02:00
parent 4bc794e42a
commit b32aed174a

View File

@@ -289,6 +289,9 @@ static const gint prime_mod [] =
static void static void
g_hash_table_set_shift (GHashTable *hash_table, gint shift) g_hash_table_set_shift (GHashTable *hash_table, gint shift)
{ {
if (shift > 31)
g_error ("adding more entries to hash table would overflow");
hash_table->size = 1 << shift; hash_table->size = 1 << shift;
hash_table->mod = prime_mod [shift]; hash_table->mod = prime_mod [shift];