*fixed a wrong hash bug with pointer, which may cause crash on some 64bit systems.

This commit is contained in:
Wang Renxin 2017-04-05 16:54:53 +08:00
parent f0154061e4
commit cf3870509a
2 changed files with 12 additions and 8 deletions

View File

@ -1,3 +1,6 @@
Apr. 5 2017
Fixed a wrong hash bug with pointer, which may cause crash on some 64bit systems
Mar. 29 2017 Mar. 29 2017
Added an alive object checker of referenced usertype Added an alive object checker of referenced usertype

View File

@ -2701,14 +2701,15 @@ static unsigned _ht_hash_string(void* ht, void* d) {
static unsigned _ht_hash_intptr(void* ht, void* d) { static unsigned _ht_hash_intptr(void* ht, void* d) {
unsigned result = 0; unsigned result = 0;
_ht_node_t* self = (_ht_node_t*)ht; _ht_node_t* self = (_ht_node_t*)ht;
intptr_t i = *(intptr_t*)d;
mb_assert(ht); mb_assert(ht);
if(self->array_size == 1) if(self->array_size == 1) {
result = 0; result = 0;
else } else {
result = (unsigned)(i % self->array_size); uintptr_t u = (uintptr_t)d;
result = (unsigned)(u % self->array_size);
}
return result; return result;
} }
@ -2723,8 +2724,8 @@ static unsigned _ht_hash_ref(void* ht, void* d) {
if(self->array_size == 1) { if(self->array_size == 1) {
result = 0; result = 0;
} else { } else {
result = (unsigned)(intptr_t)ref; uintptr_t u = (uintptr_t)ref;
result %= self->array_size; result = (unsigned)(u % self->array_size);
} }
return result; return result;
@ -2825,8 +2826,8 @@ static int _ht_cmp_string(void* d1, void* d2) {
} }
static int _ht_cmp_intptr(void* d1, void* d2) { static int _ht_cmp_intptr(void* d1, void* d2) {
intptr_t i1 = *(intptr_t*)d1; intptr_t i1 = (intptr_t)d1;
intptr_t i2 = *(intptr_t*)d2; intptr_t i2 = (intptr_t)d2;
if(i1 < i2) if(i1 < i2)
return -1; return -1;