1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +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:
tiv
2019-03-28 12:42:41 +03:00
committed by bugmaster
parent 833034f301
commit 2b2be3fb82
89 changed files with 878 additions and 580 deletions

View File

@@ -19,13 +19,14 @@
#include <StepToTopoDS_CartesianPointHasher.hxx>
//=======================================================================
//function : HashCode
//purpose :
// function : HashCode
// purpose :
//=======================================================================
Standard_Integer StepToTopoDS_CartesianPointHasher::HashCode
(const Handle(StepGeom_CartesianPoint)& K, const Standard_Integer Upper)
Standard_Integer StepToTopoDS_CartesianPointHasher::HashCode (const Handle (StepGeom_CartesianPoint)
& theCartesianPoint,
const Standard_Integer theUpperBound)
{
return ::HashCode(K,Upper);
return ::HashCode (theCartesianPoint, theUpperBound);
}
//=======================================================================

View File

@@ -33,10 +33,13 @@ public:
DEFINE_STANDARD_ALLOC
//! Returns a HasCode value for the CartesianPoint
Standard_EXPORT static Standard_Integer HashCode (const Handle(StepGeom_CartesianPoint)& K, const Standard_Integer Upper);
//! Computes a hash code for the cartesian point, in the range [1, theUpperBound]
//! @param theCartesianPoint the cartesian point 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]
Standard_EXPORT static Standard_Integer HashCode (const Handle (StepGeom_CartesianPoint) & theCartesianPoint,
Standard_Integer theUpperBound);
//! Returns True when the two CartesianPoint are the same
Standard_EXPORT static Standard_Boolean IsEqual (const Handle(StepGeom_CartesianPoint)& K1, const Handle(StepGeom_CartesianPoint)& K2);

View File

@@ -20,13 +20,14 @@
#include <StepToTopoDS_PointPairHasher.hxx>
//=======================================================================
//function : HashCode
//purpose :
// function : HashCode
// purpose :
//=======================================================================
Standard_Integer StepToTopoDS_PointPairHasher::HashCode
(const StepToTopoDS_PointPair& P, const Standard_Integer Upper)
Standard_Integer StepToTopoDS_PointPairHasher::HashCode (const StepToTopoDS_PointPair& thePointPair,
const Standard_Integer theUpperBound)
{
return (::HashCode(P.myP1,Upper) + ::HashCode(P.myP2,Upper)) % Upper;
return ::HashCode (::HashCode (thePointPair.myP1, theUpperBound) + ::HashCode (thePointPair.myP2, theUpperBound),
theUpperBound);
}
//=======================================================================

View File

@@ -33,9 +33,11 @@ public:
DEFINE_STANDARD_ALLOC
//! Returns a HasCode value for the PointPair
Standard_EXPORT static Standard_Integer HashCode (const StepToTopoDS_PointPair& K, const Standard_Integer Upper);
//! Computes a hash code for the point pair, in the range [1, theUpperBound]
//! @param thePointPair the point pair 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]
Standard_EXPORT static Standard_Integer HashCode (const StepToTopoDS_PointPair& thePointPair, Standard_Integer theUpperBound);
//! Returns True when the two PointPair are the same
Standard_EXPORT static Standard_Boolean IsEqual (const StepToTopoDS_PointPair& K1, const StepToTopoDS_PointPair& K2);