mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Fix exceptaionally rare crash bug in hash tables (happens once in every 2^32 hash lookups
darcs-hash:20061018230148-ac50b-4e67ecf1f9aeae8239c40101ae2ad6aa164c31bb.gz
This commit is contained in:
parent
bab168f1d1
commit
c7bc31fe50
1 changed files with 2 additions and 2 deletions
4
util.c
4
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 )
|
||||
|
|
Loading…
Reference in a new issue