Skip to content

Bug fixes from incremental depmod PR #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion man/depmod.8.scd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ depmod - Generate modules.dep and map files.

# SYNOPSIS

*depmod* [*-b* _basedir_] [*-m* _moduledir_] [*-o* _outdir_][*-o* _outdir_] [*-e*] [*-E* _Module.symvers_]
*depmod* [*-b* _basedir_] [*-m* _moduledir_] [*-o* _outdir_] [*-e*] [*-E* _Module.symvers_]
\ \ \ \ \ \ \ \[*-F* _System.map_] [*-n*] [*-v*] [*-A*] [*-P* _prefix_] [*-w*] [_version_]

*depmod* [*-e*] [*-E* _Module.symvers_] [*-F* _System.map_] [*-n*] [*-v*] [*-P* _prefix_]
Expand Down
7 changes: 5 additions & 2 deletions shared/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value))
hash->n_buckets = n_buckets;
hash->free_value = free_value;
hash->step = n_buckets / 32;
if (hash->step == 0)
if (hash->step < 4)
hash->step = 4;
else if (hash->step > 64)
hash->step = 64;
Expand Down Expand Up @@ -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)
Expand All @@ -258,7 +261,7 @@ int hash_del(struct hash *hash, const char *key)
hash->free_value((void *)entry->value);

entry_end = bucket->entries + bucket->used;
memmove(entry, entry + 1, (entry_end - entry) * sizeof(struct hash_entry));
memmove(entry, entry + 1, (entry_end - entry - 1) * sizeof(struct hash_entry));

bucket->used--;
hash->count--;
Expand Down
3 changes: 3 additions & 0 deletions shared/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ size_t strbuf_pushmem(struct strbuf *buf, const char *src, size_t sz)
assert(src != NULL);
assert(buf != NULL);

if (sz == 0)
return 0;

if (!strbuf_reserve_extra(buf, sz))
return 0;

Expand Down
31 changes: 31 additions & 0 deletions testsuite/test-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,37 @@ static int test_hash_iter_after_del(const struct test *t)
DEFINE_TEST(test_hash_iter_after_del,
.description = "test hash_iter, after deleting element");

static int test_hash_del(const struct test *t)
{
struct hash *h = hash_new(32, NULL);
const char *k1 = "k1";
const char *v1 = "v1";

hash_add(h, k1, v1);
hash_del(h, k1);

hash_free(h);

return 0;
}
DEFINE_TEST(test_hash_del, .description = "test add / delete a single element");

static int test_hash_del_nonexistent(const struct test *t)
{
struct hash *h = hash_new(32, NULL);
const char *k1 = "k1";
int rc;

rc = hash_del(h, k1);
assert_return(rc == -ENOENT, EXIT_FAILURE);

hash_free(h);

return 0;
}
DEFINE_TEST(test_hash_del_nonexistent,
.description = "test deleting an element that doesn't exist");

static int test_hash_free(const struct test *t)
{
struct hash *h = hash_new(8, countfreecalls);
Expand Down
1 change: 1 addition & 0 deletions testsuite/test-strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static int test_strbuf_pushmem(const struct test *t)
size_t size;

strbuf_init(&buf);
strbuf_pushmem(&buf, "", 0);
strbuf_reserve_extra(&buf, strlen(TEXT) + 1);
size = buf.size;
strbuf_pushmem(&buf, TEXT, strlen(TEXT) + 1);
Expand Down