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

@@ -86,10 +86,13 @@ private:
BRepMesh_DegreeOfFreedom myMovability;
};
inline Standard_Integer HashCode(const BRepMesh_Edge& theEdge,
const Standard_Integer theUpper)
//! Computes a hash code for the given edge, in the range [1, theUpperBound]
//! @param theEdge the edge 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]
inline Standard_Integer HashCode (const BRepMesh_Edge& theEdge, const Standard_Integer theUpperBound)
{
return theEdge.HashCode(theUpper);
return theEdge.HashCode (theUpperBound);
}
#endif

View File

@@ -54,12 +54,12 @@ public:
return myLastNode;
}
//! Returns hash code for this edge.
//! @param theUpper upper index in the container.
//! @return hash code.
inline Standard_Integer HashCode(const Standard_Integer theUpper) const
//! Computes a hash code for this oriented edge, 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]
inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{
return ::HashCode(myFirstNode + myLastNode, theUpper);
return ::HashCode (myFirstNode + myLastNode, theUpperBound);
}
//! Checks this and other edge for equality.
@@ -82,10 +82,13 @@ private:
Standard_Integer myLastNode;
};
inline Standard_Integer HashCode(const BRepMesh_OrientedEdge& theEdge,
const Standard_Integer theUpper)
//! Computes a hash code for the given oriented edge, in the range [1, theUpperBound]
//! @param theOrientedEdge the oriented edge 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]
inline Standard_Integer HashCode (const BRepMesh_OrientedEdge& theOrientedEdge, const Standard_Integer theUpperBound)
{
return theEdge.HashCode(theUpper);
return theOrientedEdge.HashCode (theUpperBound);
}
#endif

View File

@@ -91,15 +91,15 @@ public:
{
myMovability = theMovability;
}
//! Returns hash code for this triangle.
//! @param theUpper upper index in the container.
//! @return hash code.
inline Standard_Integer HashCode(const Standard_Integer theUpper) const
//! Computes a hash code for this triangle, 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]
inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{
return ::HashCode(myEdges[0] + myEdges[1] + myEdges[2], theUpper);
return ::HashCode (myEdges[0] + myEdges[1] + myEdges[2], theUpperBound);
}
//! Checks for equality with another triangle.
//! @param theOther triangle to be checked against this one.
//! @return TRUE if equal, FALSE if not.
@@ -143,10 +143,13 @@ public:
BRepMesh_DegreeOfFreedom myMovability;
};
inline Standard_Integer HashCode(const BRepMesh_Triangle& theTriangle,
const Standard_Integer theUpper)
//! Computes a hash code for the given triangle, in the range [1, theUpperBound]
//! @param theTriangle the triangle 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]
inline Standard_Integer HashCode (const BRepMesh_Triangle& theTriangle, const Standard_Integer theUpperBound)
{
return theTriangle.HashCode(theUpper);
return theTriangle.HashCode (theUpperBound);
}
#endif

View File

@@ -103,13 +103,13 @@ public:
{
myMovability = theMovability;
}
//! Returns hash code for this vertex.
//! @param theUpper upper index in the container.
//! @return hash code.
inline Standard_Integer HashCode(const Standard_Integer Upper) const
//! Computes a hash code for this vertex, 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]
inline Standard_Integer HashCode(const Standard_Integer theUpperBound) const
{
return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), Upper);
return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), theUpperBound);
}
//! Checks for equality with another vertex.
@@ -139,9 +139,13 @@ private:
BRepMesh_DegreeOfFreedom myMovability;
};
inline Standard_Integer HashCode(const BRepMesh_Vertex& me, const Standard_Integer Upper)
//! Computes a hash code for the given vertex, in the range [1, theUpperBound]
//! @param theVertex the vertex 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]
inline Standard_Integer HashCode (const BRepMesh_Vertex& theVertex, const Standard_Integer theUpperBound)
{
return me.HashCode(Upper);
return theVertex.HashCode (theUpperBound);
}
#endif