fix signed-integer-overflow issue:

Hash functions rely on 2's complement behaviour. Use unsigned integers to get that.
This commit is contained in:
Erwin Coumans
2017-05-09 16:36:11 -07:00
parent e6d1ed6ffe
commit 0d3940b8bd
3 changed files with 12 additions and 15 deletions

View File

@@ -105,9 +105,10 @@ public:
//to our success
SIMD_FORCE_INLINE unsigned int getHash()const
{
int key = m_uid;
unsigned int key = m_uid;
// Thomas Wang's hash
key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
return key;
}
};
@@ -120,7 +121,7 @@ class btHashPtr
union
{
const void* m_pointer;
int m_hashValues[2];
unsigned int m_hashValues[2];
};
public:
@@ -145,8 +146,7 @@ public:
{
const bool VOID_IS_8 = ((sizeof(void*)==8));
int key = VOID_IS_8? m_hashValues[0]+m_hashValues[1] : m_hashValues[0];
unsigned int key = VOID_IS_8? m_hashValues[0]+m_hashValues[1] : m_hashValues[0];
// Thomas Wang's hash
key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
return key;
@@ -179,7 +179,7 @@ public:
//to our success
SIMD_FORCE_INLINE unsigned int getHash()const
{
int key = m_uid;
unsigned int key = m_uid;
// Thomas Wang's hash
key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
return key;
@@ -211,7 +211,7 @@ public:
//to our success
SIMD_FORCE_INLINE unsigned int getHash()const
{
int key = m_uid;
unsigned int key = m_uid;
// Thomas Wang's hash
key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
return key;