Added protection for growing past too many entries to the hash going off the end of the primes list.

This commit is contained in:
Jon Meredith 2009-02-10 15:22:02 -07:00
parent 153d4615cd
commit c8699679c3

View file

@ -6,7 +6,7 @@
*
* Dave Smith (dsmith@thehive.com) 12/08
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
@ -75,12 +75,14 @@ static unsigned int strhash(const char *str)
hive_hash * hive_hash_new(unsigned int capacity) {
struct hive_hash *h;
int i, sind;
int i, sind = sizes_count;
capacity /= load_factor;
// JDM: This can leave sind uninitialized
for (i=0; i < sizes_count; i++)
if (sizes[i] > capacity) { sind = i; break; }
assert(sizes_count != sind);
if ((h = malloc(sizeof(struct hive_hash))) == NULL) return NULL;
if ((h->records = calloc(sizes[sind], sizeof(struct record))) == NULL) {