1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous

Operator of cast to non-const reference is declared deprecated to produce compiler warning if used (usually implicitly).

OCCT code is updated to avoid that cast, occurring when function accepting non-const reference to handle is called with handle to derived type.
For that, local variable of argument type is passed instead, and down-cast is used to get it to desired type after the call.
A few occurrences of use of uninitialized variable are corrected.
This commit is contained in:
abv
2016-02-17 17:33:18 +03:00
parent fe9b8ff2f2
commit aa00364da7
59 changed files with 395 additions and 211 deletions

View File

@@ -290,17 +290,33 @@ VrmlData_ErrorStatus VrmlData_IndexedFaceSet::Read(VrmlData_InBuffer& theBuffer)
// These four checks should be the last one to avoid their interference
// with the other tokens (e.g., coordIndex)
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texCoord"))
aStatus = ReadNode (theBuffer, myTxCoords,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_TextureCoordinate));
myTxCoords = Handle(VrmlData_TextureCoordinate)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color"))
aStatus = ReadNode (theBuffer, myColors,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Color));
myColors = Handle(VrmlData_Color)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord"))
aStatus = ReadNode (theBuffer, myCoords,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Coordinate));
myCoords = Handle(VrmlData_Coordinate)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "normal"))
aStatus = ReadNode (theBuffer, myNormals,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Normal));
myNormals = Handle(VrmlData_Normal)::DownCast (aNode);
}
if (!OK(aStatus))
break;
}

View File

@@ -144,11 +144,19 @@ VrmlData_ErrorStatus VrmlData_IndexedLineSet::Read
// These two checks should be the last one to avoid their interference
// with the other tokens (e.g., coordIndex)
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color"))
aStatus = ReadNode (theBuffer, myColors,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Color));
myColors = Handle(VrmlData_Color)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord"))
aStatus = ReadNode (theBuffer, myCoords,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Coordinate));
myCoords = Handle(VrmlData_Coordinate)::DownCast (aNode);
}
else
break;
if (!OK(aStatus))

View File

@@ -370,13 +370,21 @@ VrmlData_ErrorStatus VrmlData_ShapeNode::Read (VrmlData_InBuffer& theBuffer)
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "appearance"))
aStatus = ReadNode (theBuffer, myAppearance,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Appearance));
myAppearance = Handle(VrmlData_Appearance)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "geometry"))
aStatus = ReadNode (theBuffer, myGeometry);
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode);
myGeometry = Handle(VrmlData_Geometry)::DownCast (aNode);
// here we do not check for the Geometry type because unknown node types can
// occur (IndexedLineSet, etc.)
// STANDARD_TYPE(VrmlData_Geometry));
}
else
break;
@@ -509,14 +517,26 @@ VrmlData_ErrorStatus VrmlData_Appearance::Read (VrmlData_InBuffer& theBuffer)
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "material"))
aStatus = ReadNode (theBuffer, myMaterial,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Material));
myMaterial = Handle(VrmlData_Material)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "textureTransform"))
aStatus = ReadNode (theBuffer, myTTransform
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode
/*,STANDARD_TYPE(VrmlData_TextureTransform)*/);
myTTransform = Handle(VrmlData_TextureTransform)::DownCast (aNode);
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texture"))
aStatus = ReadNode (theBuffer, myTexture,
{
Handle(VrmlData_Node) aNode;
aStatus = ReadNode (theBuffer, aNode,
STANDARD_TYPE(VrmlData_Texture));
myTexture = Handle(VrmlData_Texture)::DownCast (aNode);
}
else
break;