mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +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:
@@ -55,10 +55,13 @@ class BOPTools_Parallel
|
||||
//! Auxiliary thread ID hasher.
|
||||
struct Hasher
|
||||
{
|
||||
static Standard_Integer HashCode(const Standard_ThreadId theKey,
|
||||
const Standard_Integer Upper)
|
||||
//! Computes a hash code for the given thread identifier, in the range [1, theUpperBound]
|
||||
//! @param theThreadId the thread identifier 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 Standard_ThreadId theThreadId, const Standard_Integer theUpperBound)
|
||||
{
|
||||
return ::HashCode((Standard_Size)theKey, Upper);
|
||||
return ::HashCode (theThreadId, theUpperBound);
|
||||
}
|
||||
|
||||
static Standard_Boolean IsEqual(const Standard_ThreadId theKey1,
|
||||
|
@@ -107,15 +107,16 @@ const TopoDS_Shape& BOPTools_Set::Shape()const
|
||||
{
|
||||
return myShape;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HashCode
|
||||
//purpose :
|
||||
// function : HashCode
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer BOPTools_Set::HashCode
|
||||
(const Standard_Integer theUpper)const
|
||||
Standard_Integer BOPTools_Set::HashCode (const Standard_Integer theUpperBound) const
|
||||
{
|
||||
return ::HashCode(mySum, theUpper);
|
||||
return ::HashCode (mySum, theUpperBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsEqual
|
||||
//purpose :
|
||||
|
@@ -54,10 +54,11 @@ BOPTools_Set& operator = (const BOPTools_Set& Other)
|
||||
Standard_EXPORT Standard_Integer NbShapes() const;
|
||||
|
||||
Standard_EXPORT Standard_Boolean IsEqual (const BOPTools_Set& aOther) const;
|
||||
|
||||
Standard_EXPORT Standard_Integer HashCode (const Standard_Integer Upper) const;
|
||||
|
||||
|
||||
//! Computes a hash code for this set, in the range [1, theUpperBound]
|
||||
//! @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]
|
||||
Standard_EXPORT Standard_Integer HashCode (Standard_Integer theUpperBound) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
@@ -30,11 +30,14 @@ class BOPTools_SetMapHasher
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
//! Computes a hash code for the given set, in the range [1, theUpperBound]
|
||||
//! @param theSet the set 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 BOPTools_Set& theSet, Standard_Integer theUpperBound);
|
||||
|
||||
|
||||
static Standard_Integer HashCode (const BOPTools_Set& aSet, const Standard_Integer Upper);
|
||||
|
||||
static Standard_Boolean IsEqual (const BOPTools_Set& aSet1, const BOPTools_Set& aSet2);
|
||||
static Standard_Boolean IsEqual (const BOPTools_Set& aSet1, const BOPTools_Set& aSet2);
|
||||
|
||||
|
||||
|
||||
|
@@ -13,15 +13,17 @@
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
//#include <BOPTools_SetMapHasher.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : HashCode
|
||||
//purpose :
|
||||
// function : HashCode
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
inline Standard_Integer BOPTools_SetMapHasher::HashCode(const BOPTools_Set& theSS,
|
||||
const Standard_Integer Upper)
|
||||
inline Standard_Integer BOPTools_SetMapHasher::HashCode (const BOPTools_Set& theSet,
|
||||
const Standard_Integer theUpperBound)
|
||||
{
|
||||
return theSS.HashCode(Upper);
|
||||
return theSet.HashCode (theUpperBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function :IsEqual
|
||||
//purpose :
|
||||
|
Reference in New Issue
Block a user