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

@@ -180,14 +180,16 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
// Traites actuellement (necessaires) :
// 1(Annotation), aussi 4(pour maillage). 5(ParamUV) traite par AutoCorrect
Handle(IGESData_GeneralModule) gmod;
Standard_Integer CN;
Standard_Integer i; // svv Jan11 2000 : porting on DEC
for (i = 1; i <= nb; i ++) {
// Subordinate (sur directs en propre seulement)
Handle(IGESData_IGESEntity) ent = themodel->Entity(i);
Standard_Integer igt = ent->TypeNumber();
if (theglib.Select (ent,gmod,CN)) {
Handle(Interface_GeneralModule) gmodule;
if (theglib.Select (ent,gmodule,CN)) {
Handle(IGESData_GeneralModule) gmod =
Handle(IGESData_GeneralModule)::DownCast (gmodule);
Interface_EntityIterator sh;
gmod->OwnSharedCase (CN,ent,sh);
for (sh.Start(); sh.More(); sh.Next()) {
@@ -301,14 +303,16 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
}
// Corrections specifiques
Handle(IGESData_GeneralModule) gmod;
Handle(IGESData_SpecificModule) smod;
Standard_Integer CN;
if (theglib.Select (ent,gmod,CN)) {
Handle(Interface_GeneralModule) gmodule;
if (theglib.Select (ent,gmodule,CN)) {
Handle(IGESData_GeneralModule) gmod =
Handle(IGESData_GeneralModule)::DownCast (gmodule);
IGESData_DirChecker DC = gmod->DirChecker(CN,ent);
done |= DC.Correct(ent);
}
Handle(IGESData_SpecificModule) smod;
if (theslib.Select (ent,smod,CN)) done |= smod->OwnCorrect (CN,ent);
return done;

View File

@@ -43,7 +43,11 @@ IGESData_FreeFormatEntity::IGESData_FreeFormatEntity () { }
Standard_Boolean IGESData_FreeFormatEntity::ParamData
(const Standard_Integer num, Interface_ParamType& ptype,
Handle(IGESData_IGESEntity)& ent, Handle(TCollection_HAsciiString)& val) const
{ return UndefinedContent()->ParamData (num,ptype,ent,val); }
{
Handle(Standard_Transient) anEnt = ent;
return UndefinedContent()->ParamData (num, ptype, anEnt, val) &&
! (ent = Handle(IGESData_IGESEntity)::DownCast (anEnt)).IsNull();
}
Interface_ParamType IGESData_FreeFormatEntity::ParamType

View File

@@ -334,11 +334,16 @@ IGESData_IGESReaderTool::IGESData_IGESReaderTool
IGESData_ParamReader& PR) const
{
Handle(Interface_Check) ach = new Interface_Check;;
Handle(IGESData_ReadWriteModule) module; Standard_Integer CN;
Handle(Interface_ReaderModule) imodule;
Standard_Integer CN;
// Les Modules font tout
if (therlib.Select(ent,module,CN))
if (therlib.Select(ent,imodule,CN))
{
Handle(IGESData_ReadWriteModule) module =
Handle(IGESData_ReadWriteModule)::DownCast (imodule);
module->ReadOwnParams(CN,ent,IR,PR);
}
else if (ent.IsNull()) {
// Pas trouve dutout
// Sending of message : Null Entity

View File

@@ -716,6 +716,7 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea
Handle(IGESData_IGESEntity)& val,
const Standard_Boolean canbenul)
{
aStatus = IGESData_EntityError;
if (!PrepareRead(PC,Standard_False)) return Standard_False;
Standard_Integer nval;
// if (!ReadingEntityNumber(theindex,amsg,nval)) return Standard_False;
@@ -730,6 +731,8 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea
thelast = Standard_True;
}
else
aStatus = IGESData_EntityOK;
return canbenul;
}
else val = GetCasted(IGESData_IGESEntity,IR->BoundEntity(nval));
@@ -745,6 +748,8 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea
//SendFail (amsg);
thelast = Standard_True;
}
else
aStatus = IGESData_EntityOK;
return canbenul;
}
}
@@ -1344,6 +1349,7 @@ Standard_Boolean IGESData_ParamReader::ReadingReal
} else if (FP.ParamType() == Interface_ParamVoid) {
val = 0.0; // DEFAULT
} else {
val = 0.0; // DEFAULT
char ssem[100];
sprintf(ssem,": not given as Real, rank %d",num);
AddFail (mess,ssem,": not given as Real, rank %d");

View File

@@ -224,6 +224,16 @@ public:
Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
//! Safe variant for arbitrary type of argument
template <class T>
Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False)
{
Handle(IGESData_IGESEntity) aVal = val;
Standard_Boolean aRes = ReadEntity (IR, PC, aStatus, type, aVal, canbenul);
val = Handle(T)::DownCast(aVal);
return aRes && (canbenul || ! val.IsNull());
}
//! Works as ReadEntity without Type, but in addition checks the
//! Type of the Entity, which must be "kind of" a given <type>
//! Then, gives the same fail cases as ReadEntity without Type,
@@ -231,6 +241,16 @@ public:
//! (in such a case, returns False and givel <val> = Null)
Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
//! Safe variant for arbitrary type of argument
template <class T>
Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False)
{
Handle(IGESData_IGESEntity) aVal = val;
Standard_Boolean aRes = ReadEntity (IR, PC, mess, type, aVal, canbenul);
val = Handle(T)::DownCast(aVal);
return aRes && (canbenul || ! val.IsNull());
}
Standard_EXPORT Standard_Boolean ReadInts (const IGESData_ParamCursor& PC, const Message_Msg& amsg, Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index = 1);
//! Reads a list of Integer values, defined by PC (with a count of

View File

@@ -104,9 +104,11 @@ void IGESData_ToolLocation::ResetDependences (const Handle(IGESData_IGESEntity)
void IGESData_ToolLocation::SetOwnAsDependent (const Handle(IGESData_IGESEntity)& ent)
{
Handle(IGESData_GeneralModule) module;
Standard_Integer CN;
if (!thelib.Select(ent,module,CN)) return;
Handle(Interface_GeneralModule) gmodule;
if (!thelib.Select(ent,gmodule,CN)) return;
Handle(IGESData_GeneralModule) module =
Handle(IGESData_GeneralModule)::DownCast (gmodule);
Interface_EntityIterator list;
module->OwnSharedCase(CN,ent,list);
// Remarque : en toute rigueur, il faudrait ignorer les entites referencees