mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +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:
@@ -16,13 +16,13 @@
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : HashCode
|
||||
//purpose :
|
||||
// function : HashCode
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer Interface_MapAsciiStringHasher::HashCode(const TCollection_AsciiString& K,
|
||||
const Standard_Integer Upper)
|
||||
Standard_Integer Interface_MapAsciiStringHasher::HashCode (const TCollection_AsciiString& theAsciiString,
|
||||
const Standard_Integer theUpperBound)
|
||||
{
|
||||
return ::HashCode(K.ToCString(),Upper);
|
||||
return ::HashCode (theAsciiString.ToCString(), theAsciiString.Length(), theUpperBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
@@ -32,9 +32,13 @@ public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
|
||||
Standard_EXPORT static Standard_Integer HashCode (const TCollection_AsciiString& K, const Standard_Integer Upper);
|
||||
|
||||
//! Computes a hash code for the given ASCII string, in the range [1, theUpperBound]
|
||||
//! @param theAsciiString the ASCII string 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 TCollection_AsciiString& theAsciiString,
|
||||
Standard_Integer theUpperBound);
|
||||
|
||||
Standard_EXPORT static Standard_Boolean IsEqual (const TCollection_AsciiString& K1, const TCollection_AsciiString& K2);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user