]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: hash_del: handle deleting a non-existing element gracefully
authorMartin Wilck <martin_wilck@gmx.de>
Fri, 15 Nov 2024 22:25:15 +0000 (23:25 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 29 Nov 2024 15:15:21 +0000 (09:15 -0600)
It can happen that bucket->entries is NULL, but bsearch is annotated
such that it's second argument must be non-NULL.

Fixes: 7db0865 ("Add simple hash implementation")
Signed-off-by: Martin Wilck <martin_wilck@gmx.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/hash.c
testsuite/test-hash.c

index 158d85d9b6ac3b6043d5be7be8f17c901a88fc52..f9a0c00cfec405b60cadbbc6a220c8729ab7e96b 100644 (file)
@@ -249,6 +249,9 @@ int hash_del(struct hash *hash, const char *key)
                .value = NULL,
        };
 
+       if (bucket->entries == NULL)
+               return -ENOENT;
+
        entry = bsearch(&se, bucket->entries, bucket->used, sizeof(struct hash_entry),
                        hash_entry_cmp);
        if (entry == NULL)
index e904111772fc185b12fa7039a635751ad3237c72..35cf06ed7d06c7902d92b41ca8c5bc0db64aeca6 100644 (file)
@@ -200,8 +200,7 @@ static int test_hash_del_nonexistent(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_del_nonexistent,
-           .description = "test deleting an element that doesn't exist",
-           .expected_fail = true);
+           .description = "test deleting an element that doesn't exist");
 
 static int test_hash_free(const struct test *t)
 {