[Uml-devel] [Bug 230350] Umbrello segfaults on opening xmi file

Oliver Kellogg okellogg at users.sourceforge.net
Wed Jan 18 19:40:44 UTC 2012


https://bugs.kde.org/show_bug.cgi?id=230350





--- Comment #5 from Oliver Kellogg <okellogg users sourceforge net>  2012-01-18 19:40:44 ---
(In reply to comment #4)
> The file shows an internal design issue, which may be triggered also by other
> conditions. 
> 
> UMLObject * UMLPackage::findObjectById(Uml::IDType id)
> 
> calls 
> 
>     return Model_Utils::findObjectInList(id, m_objects);
> 
> which is implemented as 
> 
> UMLObject* findObjectInList(Uml::IDType id, const UMLObjectList& inList)
> {
>     for (UMLObjectListIt oit(inList); oit.hasNext(); ) {
>         UMLObject *obj = oit.next();
>         if (obj->id() == id)
>             return obj;
>         UMLObject *o;
>         UMLObject::ObjectType t = obj->baseType();
>         switch (t) {
>         case UMLObject::ot_Folder:
>         case UMLObject::ot_Package:
>         case UMLObject::ot_Component:
> 
> here it calls the above mentioned UMLPackage::findObjectById 
> 
>            o = static_cast<UMLPackage*>(obj)->findObjectById(id);
> 
> Which means if the related id is not in the list for whatever reasons, there is
> an endless recursive loop. 
> 
> The question is, how to detect this condition ?

This could be solved by adding an optional arg, UMLPackage *self, at
Model_Utils::findObjectInList:

  UMLObject* findObjectInList(Uml::IDType id,
                              const UMLObjectList& inList,
                              UMLPackage *self = 0); 

and replacing the line

  o = static_cast<UMLPackage*>(obj)->findObjectById(id);

by

  {
    UMLPackage tmpPkg = static_cast<UMLPackage*>(obj);
    if (tmpPkg == self)
      return obj;
    o = tmpPkg->findObjectById(id);
  }

Beware though that this is still a pathological case. It would mean that the
UMLPackage contains itself - which most likely wreaks havoc elsewhere in the
code.
Perhaps it would be better to issue an error and return NULL in that case.

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.




More information about the umbrello-devel mailing list