From c532115a11eb1742ff53ed821685d8d975e2af0f Mon Sep 17 00:00:00 2001 From: Robert Stepanek Date: Mon, 14 Oct 2019 17:43:18 +0200 Subject: [PATCH] hash: gracefully handle lookup on zero-sized tables --- lib/hash.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/hash.c b/lib/hash.c index bdf11507bc..ba1d4b132c 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -157,9 +157,14 @@ void *hash_insert(const char *key, void *data, hash_table *table) void *hash_lookup(const char *key, hash_table *table) { - unsigned val = strhash(key) % table->size; + unsigned val; bucket *ptr; + if (!table->size) + return NULL; + + val = strhash(key) % table->size; + if (!(table->table)[val]) return NULL;