Added protection for growing past too many entries to the hash going off the end of the primes list.
This commit is contained in:
parent
153d4615cd
commit
c8699679c3
1 changed files with 4 additions and 2 deletions
|
@ -6,7 +6,7 @@
|
||||||
*
|
*
|
||||||
* Dave Smith (dsmith@thehive.com) 12/08
|
* Dave Smith (dsmith@thehive.com) 12/08
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -75,12 +75,14 @@ static unsigned int strhash(const char *str)
|
||||||
|
|
||||||
hive_hash * hive_hash_new(unsigned int capacity) {
|
hive_hash * hive_hash_new(unsigned int capacity) {
|
||||||
struct hive_hash *h;
|
struct hive_hash *h;
|
||||||
int i, sind;
|
int i, sind = sizes_count;
|
||||||
|
|
||||||
capacity /= load_factor;
|
capacity /= load_factor;
|
||||||
|
|
||||||
|
// JDM: This can leave sind uninitialized
|
||||||
for (i=0; i < sizes_count; i++)
|
for (i=0; i < sizes_count; i++)
|
||||||
if (sizes[i] > capacity) { sind = i; break; }
|
if (sizes[i] > capacity) { sind = i; break; }
|
||||||
|
assert(sizes_count != sind);
|
||||||
|
|
||||||
if ((h = malloc(sizeof(struct hive_hash))) == NULL) return NULL;
|
if ((h = malloc(sizeof(struct hive_hash))) == NULL) return NULL;
|
||||||
if ((h->records = calloc(sizes[sind], sizeof(struct record))) == NULL) {
|
if ((h->records = calloc(sizes[sind], sizeof(struct record))) == NULL) {
|
||||||
|
|
Loading…
Reference in a new issue