[umbrello-devel] [umbrello] [Bug 341709] Crash while importing C++ code from existing project

Ralf Habacker ralf.habacker at freenet.de
Thu Dec 11 12:59:00 UTC 2014


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

--- Comment #11 from Ralf Habacker <ralf.habacker at freenet.de> ---
(In reply to Ralf Habacker from comment #9)
...
> Add dynamic cast test to be sure we can trust getting zero pointer for
> invalid casts.

There is a surprising dynamic_cast problem inModel_Utils::findUMLObject()

At line 202 there is an access to the package child objects:
202:          UMLObjectList objectsInCurrentScope = pkg->containedObjects();

Child objects are supported from UMLPackage and higher derived classes.

UMLObject<- UMLCancasObject<-UMLPackage
                      <- UMLAssociation

In the crash case the package is an UMLAssociation instance, which does support
objects.

I added a dedicated dynamic_cast to check this case 
+            UMLPackage *p = dynamic_cast<UMLPackage*>(pkg);
+           qDebug() << p << pkg
            UMLObjectList objectsInCurrentScope = pkg->containedObjects();

and expected to get p == 0 but got

          UMLAssociation(0x1954da0, name = "UMLObject") 
UMLAssociation(0x1954da0, name = "UMLObject") 

which means p == 0x1954da0, which is *NOT* zero and indicates that dynamic_cast
fails in this context and result into the crash accessing invalid class
instance member.

In the opposite a simple testcase 

UMLObject *a = new UMLAssociation;
UMLObject *p = new UMLPackage;

UMLPackage *p1 = dynamic_cast<UMLPackage*>(a)
qDebug() << p1;
UMLPackage *p2 = dynamic_cast<UMLPackage*>(p)
qDebug() << p2;

returns p1 == 0 and p2 != 0 as expected

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the umbrello-devel mailing list