mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +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:
@@ -515,7 +515,8 @@ Standard_Integer StepData_StepReaderData::ReadSub(const Standard_Integer numsub,
|
||||
Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
|
||||
val = sn;
|
||||
sn->SetName (rectyp.ToCString());
|
||||
if (ReadAny (numsub,1,mess,ach,descr,sn)) return sn->Kind();
|
||||
Handle(Standard_Transient) aSN = sn;
|
||||
if (ReadAny (numsub,1,mess,ach,descr,aSN)) return sn->Kind();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
@@ -686,7 +687,11 @@ Standard_Boolean StepData_StepReaderData::ReadMember(const Standard_Integer num,
|
||||
{
|
||||
Handle(Standard_Transient) v = val;
|
||||
Handle(StepData_PDescr) nuldescr;
|
||||
if (v.IsNull()) return ReadAny (num,nump,mess,ach,nuldescr,val);
|
||||
if (v.IsNull())
|
||||
{
|
||||
return ReadAny (num,nump,mess,ach,nuldescr,v) &&
|
||||
! (val = Handle(StepData_SelectMember)::DownCast(v)).IsNull();
|
||||
}
|
||||
Standard_Boolean res = ReadAny (num,nump,mess,ach,nuldescr,v);
|
||||
if (v == val) return res;
|
||||
// changement -> refus
|
||||
@@ -886,9 +891,11 @@ Standard_Boolean StepData_StepReaderData::ReadAny(const Standard_Integer num,
|
||||
Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal;
|
||||
for(Standard_Integer i=1; i<=nbp2; i++) {
|
||||
if( Param(numsub2,i).ParamType() != Interface_ParamReal ) continue;
|
||||
Handle(StepData_SelectReal) sm1 = new StepData_SelectReal;
|
||||
if( !ReadAny(numsub2,i,mess,ach,descr,sm1) ) continue;
|
||||
aSeq->Append(sm1->Real());
|
||||
Handle(Standard_Transient) asr = new StepData_SelectReal;
|
||||
if( !ReadAny(numsub2,i,mess,ach,descr,asr) ) continue;
|
||||
Handle(StepData_SelectReal) sm1 = Handle(StepData_SelectReal)::DownCast (asr);
|
||||
if (! sm1.IsNull())
|
||||
aSeq->Append(sm1->Real());
|
||||
}
|
||||
Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,aSeq->Length());
|
||||
for(Standard_Integer nr=1; nr<=aSeq->Length(); nr++) {
|
||||
|
@@ -175,6 +175,14 @@ public:
|
||||
//! some members as Entity, some other not)
|
||||
Standard_EXPORT Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(StepData_SelectMember)& val) const;
|
||||
|
||||
//! Safe variant for arbitrary type of argument
|
||||
template <class T>
|
||||
Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(T)& val) const
|
||||
{
|
||||
Handle(StepData_SelectMember) aVal = val;
|
||||
return ReadMember (num, nump, mess, ach, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull();
|
||||
}
|
||||
|
||||
//! reads parameter <nump> of record <num> into a Field,
|
||||
//! controlled by a Parameter Descriptor (PDescr), which controls
|
||||
//! its allowed type(s) and value
|
||||
@@ -230,6 +238,14 @@ public:
|
||||
//! is an Entity but is not Kind of required type
|
||||
Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& ent) const;
|
||||
|
||||
//! Safe variant for arbitrary type of argument
|
||||
template <class T>
|
||||
Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(T)& ent) const
|
||||
{
|
||||
Handle(Standard_Transient) anEnt = ent;
|
||||
return ReadEntity (num, nump, mess, ach, atype, anEnt) && ! (ent = Handle(T)::DownCast(anEnt)).IsNull();
|
||||
}
|
||||
|
||||
//! Same as above, but a SelectType checks Type Matching, and
|
||||
//! records the read Entity (see method Value from SelectType)
|
||||
Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, StepData_SelectType& sel) const;
|
||||
|
@@ -211,9 +211,14 @@ Standard_Boolean StepData_StepReaderTool::AnalyseRecord
|
||||
Handle(Interface_Check)& acheck)
|
||||
{
|
||||
DeclareAndCast(StepData_StepReaderData,stepdat,Data());
|
||||
Handle(StepData_ReadWriteModule) module; Standard_Integer CN;
|
||||
if (therlib.Select(anent,module,CN))
|
||||
Handle(Interface_ReaderModule) imodule;
|
||||
Standard_Integer CN;
|
||||
if (therlib.Select(anent,imodule,CN))
|
||||
{
|
||||
Handle(StepData_ReadWriteModule) module =
|
||||
Handle(StepData_ReadWriteModule)::DownCast (imodule);
|
||||
module->ReadStep(CN,stepdat,num,acheck,anent);
|
||||
}
|
||||
else {
|
||||
// Pas trouve : tenter UndefinedEntity de StepData
|
||||
DeclareAndCast(StepData_UndefinedEntity,und,anent);
|
||||
|
Reference in New Issue
Block a user