From: srn Date: Thu, 14 Dec 2006 11:37:53 +0000 (+0000) Subject: Added additional checks of input parameters X-Git-Tag: SALOMEDS_UnitTests_1_2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=579535c2667cb6e7182979e14e76a0c97c9f9e52;p=modules%2Fkernel.git Added additional checks of input parameters --- diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx index 9a9776d30..8bc31e415 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx @@ -87,6 +87,9 @@ Standard_Boolean SALOMEDSImpl_AttributeTreeNode::Append (const Handle(SALOMEDSIm if (!(TN->ID() == myTreeID) ) Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::Append : uncompatible GUID"); + if(TN->Label() == Label()) + Standard_Failure::Raise("Attempt of self linking"); + Handle(SALOMEDSImpl_AttributeTreeNode) bid; TN->SetNext(bid); // Deconnects from next. @@ -122,6 +125,9 @@ Standard_Boolean SALOMEDSImpl_AttributeTreeNode::Prepend (const Handle(SALOMEDSI if (!(TN->ID() == myTreeID) ) Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::Prepend : uncompatible GUID"); + if(TN->Label() == Label()) + Standard_Failure::Raise("Attempt of self linking"); + Handle(SALOMEDSImpl_AttributeTreeNode) bid; TN->SetPrevious(bid); if (HasFirst()) { @@ -151,6 +157,9 @@ Standard_Boolean SALOMEDSImpl_AttributeTreeNode::InsertBefore (const Handle(SALO if (!(TN->ID() == myTreeID) ) Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::InsertBefore : uncompatible GUID"); + if(TN->Label() == Label()) + Standard_Failure::Raise("Attempt of self linking"); + TN->SetFather(GetFather()); TN->SetPrevious(GetPrevious()); TN->SetNext(this); @@ -175,6 +184,9 @@ Standard_Boolean SALOMEDSImpl_AttributeTreeNode::InsertAfter (const Handle(SALOM { CheckLocked(); + if(TN->Label() == Label()) + Standard_Failure::Raise("Attempt of self linking"); + if (!(TN->ID() == myTreeID) ) Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::InsertAfter : uncompatible GUID"); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx index e5ff80494..7b6e40fb8 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -499,10 +499,24 @@ Handle(TDF_Attribute) SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const Han } if (strncmp(aTypeOfAttribute.ToCString(), "AttributeUserID",15) == 0 ) { + Standard_GUID aUserGUID; + if (strcmp(aTypeOfAttribute.ToCString(), "AttributeUserID") == 0) { + aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID(); + } else { + char* aGUIDString = new char[40]; + char* aType = (char*)aTypeOfAttribute.ToCString(); + sprintf(aGUIDString, &(aType[15])); + if(!Standard_GUID::CheckGUIDFormat(aGUIDString)) { + delete(aGUIDString); + return NULL; + } + aUserGUID = Standard_GUID(aGUIDString); // create tree node GUID by name + delete(aGUIDString); + } Handle(SALOMEDSImpl_AttributeUserID) anAttr; if (!Lab.FindAttribute(SALOMEDSImpl_AttributeUserID::DefaultID(), anAttr)) { CheckLocked(); - anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, SALOMEDSImpl_AttributeUserID::DefaultID()); + anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID); } return anAttr; } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx index 6a20fec57..3f6f339ce 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx @@ -165,6 +165,8 @@ bool SALOMEDSImpl_UseCaseBuilder::AppendTo(const Handle(SALOMEDSImpl_SObject)& t if(_root.IsNull() || theFather.IsNull() || theObject.IsNull()) return false; TDF_Label aFatherLabel = theFather->GetLabel(), aLabel = theObject->GetLabel(); + if(aFatherLabel == aLabel) return false; + Handle(SALOMEDSImpl_AttributeTreeNode) aFather, aNode; if(aFatherLabel.IsNull()) return false; @@ -191,6 +193,8 @@ bool SALOMEDSImpl_UseCaseBuilder::InsertBefore(const Handle(SALOMEDSImpl_SObject if(_root.IsNull() || theFirst.IsNull() || theNext.IsNull()) return false; TDF_Label aFirstLabel = theFirst->GetLabel(), aLabel= theNext->GetLabel(); + if(aFirstLabel == aLabel) return false; + Handle(SALOMEDSImpl_AttributeTreeNode) aFirstNode, aNode; if(aFirstLabel.IsNull()) return false; @@ -320,7 +324,7 @@ TCollection_AsciiString SALOMEDSImpl_UseCaseBuilder::GetName() { TCollection_AsciiString aString; if(_root.IsNull()) return aString; - + Handle(SALOMEDSImpl_AttributeName) aName; if (!_root->FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) return aString; aString = TCollection_AsciiString(aName->Value());