Skip to content

Commit

Permalink
Fix more int overflow issues in hashtable
Browse files Browse the repository at this point in the history
Previous commit fixes the main hash addressing, this adds further
repairs to hash expansion and hash table walker.

HASHPOWER_MAX stays at 32, since the computed hashvalue is 32bit and
going beyond that would break things rather badly :)
  • Loading branch information
dormando committed Feb 9, 2022
1 parent c22c464 commit f393a1a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static bool expanding = false;
* During expansion we migrate values with bucket granularity; this is how
* far we've gotten so far. Ranges from 0 .. hashsize(hashpower - 1) - 1.
*/
static unsigned int expand_bucket = 0;
static uint64_t expand_bucket = 0;

void assoc_init(const int hashtable_init) {
if (hashtable_init) {
Expand All @@ -69,7 +69,7 @@ void assoc_init(const int hashtable_init) {

item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) {
item *it;
unsigned int oldbucket;
uint64_t oldbucket;

if (expanding &&
(oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
Expand Down Expand Up @@ -98,7 +98,7 @@ item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) {

static item** _hashitem_before (const char *key, const size_t nkey, const uint32_t hv) {
item **pos;
unsigned int oldbucket;
uint64_t oldbucket;

if (expanding &&
(oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
Expand Down Expand Up @@ -147,7 +147,7 @@ void assoc_start_expand(uint64_t curr_items) {

/* Note: this isn't an assoc_update. The key must not already exist to call this */
int assoc_insert(item *it, const uint32_t hv) {
unsigned int oldbucket;
uint64_t oldbucket;

// assert(assoc_find(ITEM_key(it), it->nkey) == 0); /* shouldn't have duplicately named things defined */

Expand Down Expand Up @@ -199,7 +199,7 @@ static void *assoc_maintenance_thread(void *arg) {
/* There is only one expansion thread, so no need to global lock. */
for (ii = 0; ii < hash_bulk_move && expanding; ++ii) {
item *it, *next;
unsigned int bucket;
uint64_t bucket;
void *item_lock = NULL;

/* bucket = hv & hashmask(hashpower) =>the bucket of hash table
Expand Down Expand Up @@ -290,10 +290,10 @@ void stop_assoc_maintenance_thread() {
}

struct assoc_iterator {
unsigned int bucket;
bool bucket_locked;
uint64_t bucket;
item *it;
item *next;
bool bucket_locked;
};

void *assoc_get_iterator(void) {
Expand Down

0 comments on commit f393a1a

Please sign in to comment.