1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +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

@@ -32,11 +32,14 @@ class MAT2d_MapBiIntHasher
public:
DEFINE_STANDARD_ALLOC
//! Computes a 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 MAT2d_BiInt& theKey, const Standard_Integer theUpperBound);
static Standard_Integer HashCode (const MAT2d_BiInt& Key1, const Standard_Integer Upper);
static Standard_Boolean IsEqual (const MAT2d_BiInt& Key1, const MAT2d_BiInt& Key2);
static Standard_Boolean IsEqual (const MAT2d_BiInt& Key1, const MAT2d_BiInt& Key2);

View File

@@ -18,13 +18,12 @@
#include <TColStd_MapIntegerHasher.hxx>
//=======================================================================
//function : HashCode
//purpose :
// function : HashCode
// purpose :
//=======================================================================
inline Standard_Integer MAT2d_MapBiIntHasher::HashCode
(const MAT2d_BiInt& Key1, const Standard_Integer upper)
inline Standard_Integer MAT2d_MapBiIntHasher::HashCode (const MAT2d_BiInt& theKey, const Standard_Integer theUpperBound)
{
return TColStd_MapIntegerHasher::HashCode(Key1.FirstIndex(),upper);
return TColStd_MapIntegerHasher::HashCode (theKey.FirstIndex(), theUpperBound);
}
//=======================================================================