mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0030550: Coding - Integer overflow in Standard_CString HashCodes
0030551: Foundation Classes - Integer overflow in NCollection_CellFilter HashCode Signed integers are not used in hash code functions now to prevent undefined behavior on left shift operations with signed integers. A possibility of negative values of hash codes is eliminated. INT_MAX → IntegerLast() in hash code functions. All found hash code functions behaves uniformly now: they return a value in the range [1, theUpperBound]. Relevant comments are added to such functions.
This commit is contained in:
@@ -23,11 +23,15 @@
|
||||
//purpose : Function is required to call the global function HashCode.
|
||||
//=======================================================================
|
||||
|
||||
template <class TheKeyType>
|
||||
inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey,
|
||||
const Standard_Integer Upper)
|
||||
//! Returns hash code for the given key, in the range [1, theUpperBound]
|
||||
//! @tparam TheKeyType the type of the given key
|
||||
//! @param theKey the key which hash code is to be computed
|
||||
//! @param theUpperBound the upper bound of the range a computing hash code must be within
|
||||
//! @return a computed hash code, in the range [1, theUpperBound]
|
||||
template <class TheKeyType>
|
||||
inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey, const Standard_Integer theUpperBound)
|
||||
{
|
||||
return HashCode (theKey, Upper);
|
||||
return HashCode (theKey, theUpperBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -65,11 +69,15 @@ inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1,
|
||||
*/
|
||||
template <class TheKeyType> class NCollection_DefaultHasher {
|
||||
public:
|
||||
//
|
||||
static Standard_Integer HashCode(const TheKeyType& theKey,
|
||||
const Standard_Integer Upper) {
|
||||
return HashCode_Proxy(theKey, Upper);
|
||||
//! Returns hash code for the given key, in the range [1, theUpperBound]
|
||||
//! @param theKey the key which hash code is to be computed
|
||||
//! @param theUpperBound the upper bound of the range a computing hash code must be within
|
||||
//! @return a computed hash code, in the range [1, theUpperBound]
|
||||
static Standard_Integer HashCode (const TheKeyType& theKey, const Standard_Integer theUpperBound)
|
||||
{
|
||||
return HashCode_Proxy (theKey, theUpperBound);
|
||||
}
|
||||
|
||||
//
|
||||
static Standard_Boolean IsEqual(const TheKeyType& theKey1,
|
||||
const TheKeyType& theKey2) {
|
||||
|
Reference in New Issue
Block a user