0030550: Coding - Integer overflow in Standard_CString HashCodes
[occt.git] / src / Standard / Standard_Address.hxx
index 6328037..2919d45 100644 (file)
 
 #include <Standard_Integer.hxx>
 
-//============================================================================
-//==== HashCode : Returns a HashCode CString
-//============================================================================
-inline Standard_Integer HashCode (const Standard_Address Value, 
-                                 const Standard_Integer Upper)
+//! Returns a hash code of the given memory pointer
+//! @param thePointer the memory pointer which hash code it to be computed
+//! @param theUpperBound the upper bound of the range a resulting hash code must be within
+//! @return a value of a computed hash code, in range [1, UpperBound]
+inline Standard_Integer HashCode (const void* const thePointer, const Standard_Integer theUpperBound)
 {
-  union {Standard_Address L ;
-         Standard_Integer I[2] ;} U ;
-  U.I[0] = 0 ;
-  U.I[1] = 0 ;
-  U.L = Value;
-  return HashCode( ( ( U.I[0] ^ U.I[1] ) & 0x7fffffff )  , Upper ) ;
+  union
+  {
+    const void*      L;
+    Standard_Integer I[2];
+  } U;
+
+  U.I[0] = 0;
+  U.I[1] = 0;
+  U.L    = thePointer;
+
+  return HashCode (U.I[0] ^ U.I[1], theUpperBound);
 }
 
 //============================================================================