summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-12-16 18:49:28 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-12-16 19:33:01 +0100
commit8465c1a05593434aa24a8ab9a0e8e023ce3967d2 (patch)
treedf5f7c1ceca2afbbd79ae71a5cf00fa8a4fb84d1
parentabd76e02864163b6a627e5c5722cb4d6a8d35501 (diff)
downloadglib-8465c1a05593434aa24a8ab9a0e8e023ce3967d2.tar.gz
ghash: Use unsigned types for number of nodes and occupied ones
It has always been considered an unsigned value, and we also returned it straight as int in g_hash_table_size(), but it was actually used as an int. So use the same type of g_hash_table_size(). Not using more standard unsigned not to risk that it may different from the guint typedef.
-rw-r--r--glib/ghash.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/glib/ghash.c b/glib/ghash.c
index 64edc0a34..132e3ac5e 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -260,8 +260,8 @@ struct _GHashTable
gsize size;
gint mod;
guint mask;
- gint nnodes;
- gint noccupied; /* nnodes + tombstones */
+ guint nnodes;
+ guint noccupied; /* nnodes + tombstones */
guint have_big_keys : 1;
guint have_big_values : 1;
@@ -548,6 +548,7 @@ g_hash_table_remove_node (GHashTable *hash_table,
g_hash_table_assign_key_or_value (hash_table->keys, i, hash_table->have_big_keys, NULL);
g_hash_table_assign_key_or_value (hash_table->values, i, hash_table->have_big_values, NULL);
+ g_assert (hash_table->nnodes > 0);
hash_table->nnodes--;
if (notify && hash_table->key_destroy_func)
@@ -909,8 +910,8 @@ g_hash_table_resize (GHashTable *hash_table)
static inline void
g_hash_table_maybe_resize (GHashTable *hash_table)
{
- gint noccupied = hash_table->noccupied;
- gint size = hash_table->size;
+ gsize noccupied = hash_table->noccupied;
+ gsize size = hash_table->size;
if ((size > hash_table->nnodes * 4 && size > 1 << HASH_TABLE_MIN_SHIFT) ||
(size <= noccupied + (noccupied / 16)))
@@ -2338,7 +2339,7 @@ g_hash_table_get_keys_as_array (GHashTable *hash_table,
if (HASH_IS_REAL (hash_table->hashes[i]))
result[j++] = g_hash_table_fetch_key_or_value (hash_table->keys, i, hash_table->have_big_keys);
}
- g_assert_cmpint (j, ==, hash_table->nnodes);
+ g_assert (j == hash_table->nnodes);
result[j] = NULL;
if (length)
@@ -2381,7 +2382,7 @@ g_hash_table_get_keys_as_ptr_array (GHashTable *hash_table)
hash_table->keys, i, hash_table->have_big_keys));
}
}
- g_assert (array->len == (guint) hash_table->nnodes);
+ g_assert (array->len == hash_table->nnodes);
return array;
}
@@ -2456,7 +2457,7 @@ g_hash_table_get_values_as_ptr_array (GHashTable *hash_table)
hash_table->values, i, hash_table->have_big_values));
}
}
- g_assert (array->len == (guint) hash_table->nnodes);
+ g_assert (array->len == hash_table->nnodes);
return array;
}