Prevent division by zero in linkhash.

If a linkhash with a size of zero is created, then modulo operations
are prone to division by zero operations.

Purely protective measure against bad usage.
This commit is contained in:
Tobias Stoeckmann
2020-05-04 19:46:45 +02:00
parent 099016b7e8
commit 77d935b7ae

View File

@@ -12,6 +12,7 @@
#include "config.h"
#include <assert.h>
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
@@ -499,6 +500,8 @@ struct lh_table *lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *h
int i;
struct lh_table *t;
/* Allocate space for elements to avoid divisions by zero. */
assert(size > 0);
t = (struct lh_table *)calloc(1, sizeof(struct lh_table));
if (!t)
return NULL;