From c8699679c3803adc23c336bd5e82d35158dd8474 Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Tue, 10 Feb 2009 15:22:02 -0700 Subject: [PATCH] Added protection for growing past too many entries to the hash going off the end of the primes list. --- c_src/hive_hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/c_src/hive_hash.c b/c_src/hive_hash.c index df1fb17..883ce44 100644 --- a/c_src/hive_hash.c +++ b/c_src/hive_hash.c @@ -6,7 +6,7 @@ * * Dave Smith (dsmith@thehive.com) 12/08 */ - +#include #include #include #include @@ -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) {