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

@@ -13,12 +13,17 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline Standard_Integer IntTools_SurfaceRangeSampleMapHasher::HashCode(const IntTools_SurfaceRangeSample& K,
const Standard_Integer Upper) {
// return (((K.GetDepthU() % Upper) ^ (K.GetDepthV() % Upper)) % Upper);
return ((K.GetIndexU() * K.GetIndexV()) % Upper);
//=======================================================================
// function : HashCode
// purpose :
//=======================================================================
inline Standard_Integer IntTools_SurfaceRangeSampleMapHasher::HashCode (const IntTools_SurfaceRangeSample& theKey,
const Standard_Integer theUpperBound)
{
// return (((K.GetDepthU() % Upper) ^ (K.GetDepthV() % Upper)) % Upper);
return ::HashCode (theKey.GetIndexU() * theKey.GetIndexV(), theUpperBound);
}
inline Standard_Boolean IntTools_SurfaceRangeSampleMapHasher::IsEqual(const IntTools_SurfaceRangeSample& S1,
const IntTools_SurfaceRangeSample& S2) {
return S1.IsEqual(S2);