Skip to content

Commit 588c265

Browse files
committed
Improve handling of null pointers in link properties
1 parent f48f8bf commit 588c265

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

src/App/PropertyLinks.cpp

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ PropertyLinkList::~PropertyLinkList()
224224
// before accessing internals make sure the object is not about to be destroyed
225225
// otherwise the backlink contains dangling pointers
226226
if (!parent->testStatus(ObjectStatus::Destroy)) {
227-
for(auto *obj : _lValueList)
228-
obj->_removeBackLink(parent);
227+
for(auto *obj : _lValueList) {
228+
if (obj)
229+
obj->_removeBackLink(parent);
230+
}
229231
}
230232
}
231233
#endif
@@ -251,8 +253,10 @@ void PropertyLinkList::setValue(DocumentObject* lValue)
251253
// before accessing internals make sure the object is not about to be destroyed
252254
// otherwise the backlink contains dangling pointers
253255
if (!parent->testStatus(ObjectStatus::Destroy)) {
254-
for(auto *obj : _lValueList)
255-
obj->_removeBackLink(parent);
256+
for(auto *obj : _lValueList) {
257+
if (obj)
258+
obj->_removeBackLink(parent);
259+
}
256260
if (lValue)
257261
lValue->_addBackLink(parent);
258262
}
@@ -282,10 +286,14 @@ void PropertyLinkList::setValues(const std::vector<DocumentObject*>& lValue)
282286
// before accessing internals make sure the object is not about to be destroyed
283287
// otherwise the backlink contains dangling pointers
284288
if (!parent->testStatus(ObjectStatus::Destroy)) {
285-
for(auto *obj : _lValueList)
286-
obj->_removeBackLink(parent);
287-
for(auto *obj : lValue)
288-
obj->_addBackLink(parent);
289+
for(auto *obj : _lValueList) {
290+
if (obj)
291+
obj->_removeBackLink(parent);
292+
}
293+
for(auto *obj : lValue) {
294+
if (obj)
295+
obj->_addBackLink(parent);
296+
}
289297
}
290298
}
291299
#endif
@@ -651,8 +659,10 @@ PropertyLinkSubList::~PropertyLinkSubList()
651659
// before accessing internals make sure the object is not about to be destroyed
652660
// otherwise the backlink contains dangling pointers
653661
if (!parent->testStatus(ObjectStatus::Destroy)) {
654-
for(auto *obj : _lValueList)
655-
obj->_removeBackLink(parent);
662+
for(auto *obj : _lValueList) {
663+
if (obj)
664+
obj->_removeBackLink(parent);
665+
}
656666
}
657667
}
658668
#endif
@@ -678,8 +688,10 @@ void PropertyLinkSubList::setValue(DocumentObject* lValue,const char* SubName)
678688
// before accessing internals make sure the object is not about to be destroyed
679689
// otherwise the backlink contains dangling pointers
680690
if (!parent->testStatus(ObjectStatus::Destroy)) {
681-
for(auto *obj : _lValueList)
682-
obj->_removeBackLink(parent);
691+
for(auto *obj : _lValueList) {
692+
if (obj)
693+
obj->_removeBackLink(parent);
694+
}
683695
if (lValue)
684696
lValue->_addBackLink(parent);
685697
}
@@ -716,13 +728,17 @@ void PropertyLinkSubList::setValues(const std::vector<DocumentObject*>& lValue,c
716728
if (!parent->testStatus(ObjectStatus::Destroy)) {
717729
//_lValueList can contain items multiple times, but we trust the document
718730
//object to ensure that this works
719-
for(auto *obj : _lValueList)
720-
obj->_removeBackLink(parent);
731+
for(auto *obj : _lValueList) {
732+
if (obj)
733+
obj->_removeBackLink(parent);
734+
}
721735

722736
//maintain backlinks. lValue can contain items multiple times, but we trust the document
723737
//object to ensure that the backlink is only added once
724-
for(auto *obj : lValue)
725-
obj->_addBackLink(parent);
738+
for(auto *obj : lValue) {
739+
if (obj)
740+
obj->_addBackLink(parent);
741+
}
726742
}
727743
}
728744
#endif
@@ -752,13 +768,17 @@ void PropertyLinkSubList::setValues(const std::vector<DocumentObject*>& lValue,c
752768
if (!parent->testStatus(ObjectStatus::Destroy)) {
753769
//_lValueList can contain items multiple times, but we trust the document
754770
//object to ensure that this works
755-
for(auto *obj : _lValueList)
756-
obj->_removeBackLink(parent);
771+
for(auto *obj : _lValueList) {
772+
if (obj)
773+
obj->_removeBackLink(parent);
774+
}
757775

758776
//maintain backlinks. lValue can contain items multiple times, but we trust the document
759777
//object to ensure that the backlink is only added once
760-
for(auto *obj : lValue)
761-
obj->_addBackLink(parent);
778+
for(auto *obj : lValue) {
779+
if (obj)
780+
obj->_addBackLink(parent);
781+
}
762782
}
763783
}
764784
#endif
@@ -780,8 +800,10 @@ void PropertyLinkSubList::setValue(DocumentObject* lValue, const std::vector<str
780800
if (!parent->testStatus(ObjectStatus::Destroy)) {
781801
//_lValueList can contain items multiple times, but we trust the document
782802
//object to ensure that this works
783-
for(auto *obj : _lValueList)
784-
obj->_removeBackLink(parent);
803+
for(auto *obj : _lValueList) {
804+
if (obj)
805+
obj->_removeBackLink(parent);
806+
}
785807

786808
//maintain backlinks. lValue can contain items multiple times, but we trust the document
787809
//object to ensure that the backlink is only added once
@@ -1020,10 +1042,18 @@ void PropertyLinkSubList::Save (Base::Writer &writer) const
10201042
writer.Stream() << writer.ind() << "<LinkSubList count=\"" << getSize() <<"\">" << endl;
10211043
writer.incInd();
10221044
for (int i = 0; i < getSize(); i++) {
1023-
writer.Stream() << writer.ind() <<
1024-
"<Link " <<
1025-
"obj=\"" << _lValueList[i]->getNameInDocument() << "\" " <<
1026-
"sub=\"" << _lSubList[i] << "\"/>" << endl;
1045+
if (_lValueList[i]) {
1046+
writer.Stream() << writer.ind() <<
1047+
"<Link " <<
1048+
"obj=\"" << _lValueList[i]->getNameInDocument() << "\" " <<
1049+
"sub=\"" << _lSubList[i] << "\"/>" << endl;
1050+
}
1051+
else {
1052+
writer.Stream() << writer.ind() <<
1053+
"<Link " <<
1054+
"obj=\"\" " <<
1055+
"sub=\"" << _lSubList[i] << "\"/>" << endl;
1056+
}
10271057
}
10281058

10291059
writer.decInd();

0 commit comments

Comments
 (0)