mirror of
https://github.com/json-c/json-c.git
synced 2026-03-23 15:09:07 +08:00
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:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.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;
|
int i;
|
||||||
struct lh_table *t;
|
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));
|
t = (struct lh_table *)calloc(1, sizeof(struct lh_table));
|
||||||
if (!t)
|
if (!t)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user