From c7bc31fe505bcc762afccf16ca77653161d0ed3b Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 19 Oct 2006 09:01:48 +1000 Subject: [PATCH] Fix exceptaionally rare crash bug in hash tables (happens once in every 2^32 hash lookups darcs-hash:20061018230148-ac50b-4e67ecf1f9aeae8239c40101ae2ad6aa164c31bb.gz --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 3f7233175..b2e28130a 100644 --- a/util.c +++ b/util.c @@ -207,7 +207,7 @@ static int hash_search( hash_table_t *h, int pos; hv = h->hash_func( key ); - pos = abs(hv) % h->size; + pos = (hv & 0x7fffffff) % h->size; while(1) { if( (h->arr[pos].key == 0 ) || @@ -370,7 +370,7 @@ void hash_remove( hash_table_t *h, { int hv = h->hash_func( h->arr[next_pos].key ); - int ideal_pos = abs( hv ) % h->size; + int ideal_pos = ( hv & 0x7fffffff) % h->size; int dist_old = (next_pos - ideal_pos + h->size)%h->size; int dist_new = (pos - ideal_pos + h->size)%h->size; if ( dist_new < dist_old )