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
+7 -4
View File
@@ -92,12 +92,15 @@ public:
return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) ||
(myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
}
//
//! Returns hash code
Standard_Integer HashCode (const Standard_Integer theUpper) const
//! Computes a hash code for this couple, 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_Integer HashCode (const Standard_Integer theUpperBound) const
{
return ::HashCode(myIndex1 + myIndex2, theUpper);
return ::HashCode (myIndex1 + myIndex2, theUpperBound);
}
// Dump
Standard_EXPORT void Dump (const Standard_Integer v) const;
+8 -5
View File
@@ -24,13 +24,16 @@ class IntPolyh_Couple;
class IntPolyh_CoupleMapHasher
{
public:
static Standard_Integer HashCode(const IntPolyh_Couple& theCouple,
const Standard_Integer Upper)
//! Computes a hash code for the given couple, in the range [1, theUpperBound]
//! @param theCouple the couple 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 IntPolyh_Couple& theCouple, const Standard_Integer theUpperBound)
{
return theCouple.HashCode(Upper);
return theCouple.HashCode (theUpperBound);
}
static Standard_Boolean IsEqual(const IntPolyh_Couple& theCouple1,
const IntPolyh_Couple& theCouple2)
{