mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 08:51:14 -03: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:
4
util.c
4
util.c
@@ -207,7 +207,7 @@ static int hash_search( hash_table_t *h,
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
hv = h->hash_func( key );
|
hv = h->hash_func( key );
|
||||||
pos = abs(hv) % h->size;
|
pos = (hv & 0x7fffffff) % h->size;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
if( (h->arr[pos].key == 0 ) ||
|
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 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_old = (next_pos - ideal_pos + h->size)%h->size;
|
||||||
int dist_new = (pos - ideal_pos + h->size)%h->size;
|
int dist_new = (pos - ideal_pos + h->size)%h->size;
|
||||||
if ( dist_new < dist_old )
|
if ( dist_new < dist_old )
|
||||||
|
|||||||
Reference in New Issue
Block a user