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:
@@ -15,10 +15,15 @@
|
||||
#include <Transfer_Finder.hxx>
|
||||
#include <Transfer_FindHasher.hxx>
|
||||
|
||||
Standard_Integer Transfer_FindHasher::HashCode
|
||||
(const Handle(Transfer_Finder)& K, const Standard_Integer Upper)
|
||||
|
||||
//============================================================================
|
||||
// function : HashCode
|
||||
// purpose :
|
||||
//============================================================================
|
||||
Standard_Integer Transfer_FindHasher::HashCode (const Handle (Transfer_Finder) & theFinder,
|
||||
const Standard_Integer theUpperBound)
|
||||
{
|
||||
return ((K->GetHashCode() - 1) % Upper) + 1;
|
||||
return ::HashCode (theFinder->GetHashCode() - 1, theUpperBound);
|
||||
}
|
||||
|
||||
Standard_Boolean Transfer_FindHasher::IsEqual
|
||||
|
@@ -39,11 +39,14 @@ public:
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
|
||||
//! Returns a HashCode in the range <0,Upper> for a Finder :
|
||||
//! asks the Finder its HashCode then transforms it to be in the
|
||||
//! required range
|
||||
Standard_EXPORT static Standard_Integer HashCode (const Handle(Transfer_Finder)& K, const Standard_Integer Upper);
|
||||
|
||||
//! Returns hash code for the given finder, in the range [1, theUpperBound].
|
||||
//! Asks the finder its hash code, then transforms it to be in the required range
|
||||
//! @param theFinder the finder 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 (Transfer_Finder) & theFinder,
|
||||
Standard_Integer theUpperBound);
|
||||
|
||||
//! Returns True if two keys are the same.
|
||||
//! The test does not work on the Finders themselves but by
|
||||
//! calling their methods Equates
|
||||
|
Reference in New Issue
Block a user