hashmap: check if identical hash_ops is specified if already allocated

This commit is contained in:
Yu Watanabe
2025-05-08 05:58:33 +09:00
parent 472379925c
commit bc169c4fa2
3 changed files with 17 additions and 22 deletions
+3 -10
View File
@@ -419,17 +419,10 @@ TEST(hashmap_remove_and_replace) {
TEST(hashmap_ensure_allocated) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
int r;
r = hashmap_ensure_allocated(&m, &string_hash_ops);
assert_se(r == 1);
r = hashmap_ensure_allocated(&m, &string_hash_ops);
assert_se(r == 0);
/* different hash ops shouldn't matter at this point */
r = hashmap_ensure_allocated(&m, &trivial_hash_ops);
assert_se(r == 0);
ASSERT_OK_POSITIVE(hashmap_ensure_allocated(&m, &string_hash_ops));
ASSERT_OK_ZERO(hashmap_ensure_allocated(&m, &string_hash_ops));
ASSERT_SIGNAL(hashmap_ensure_allocated(&m, &trivial_hash_ops), SIGABRT);
}
TEST(hashmap_foreach_key) {