From 7be853e63785276338a4c4d9e5be084f24114bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Sat, 5 Jun 2010 12:06:41 +0300 Subject: all: rework how arrays work Instead of having a null pointer, use a dummy array which just says the array is empty. This helps in multiple places of the code which would otherwise need explicitly need to check first if the array exists. This has been cause of multiple seg.faults in the past as the array check is easily omitted. This also removes (or fixes) all existing checks accordingly. --- src/hash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/hash.c') diff --git a/src/hash.c b/src/hash.c index c85a29d..1657bcc 100644 --- a/src/hash.c +++ b/src/hash.c @@ -16,14 +16,15 @@ void apk_hash_init(struct apk_hash *h, const struct apk_hash_ops *ops, int num_buckets) { h->ops = ops; - h->buckets = apk_hash_array_resize(NULL, num_buckets); + apk_hash_array_init(&h->buckets); + apk_hash_array_resize(&h->buckets, num_buckets); h->num_items = 0; } void apk_hash_free(struct apk_hash *h) { apk_hash_foreach(h, (apk_hash_enumerator_f) h->ops->delete_item, NULL); - free(h->buckets); + apk_hash_array_free(&h->buckets); } int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx) -- cgit v1.2.3