[Uml-devel] KDE/kdesdk/umbrello/umbrello
Ralf Habacker
Ralf.Habacker at freenet.de
Mon Jan 26 22:39:44 UTC 2009
SVN commit 917128 by habacker:
crash fix: ignore some zero pointers - they may be valid
To reduce the number of thoses crashes now and to be able to trace
those cases in the future a macro uIgnoreZeroPtr(a) has been defined.
It prints a debug message where the pointer ignore occurs and
continues in the related loop. This macro is added to places
where possible zero pointers may be possible.
M +19 -1 classifier.cpp
M +11 -2 umlcanvasobject.cpp
M +2 -0 umlnamespace.h
--- trunk/KDE/kdesdk/umbrello/umbrello/classifier.cpp #917127:917128
@@ -287,6 +287,7 @@
*/
bool UMLClassifier::addOperation(UMLOperation* op, int position )
{
+ Q_ASSERT(op);
if (m_List.indexOf(op) != -1) {
uDebug() << "findRef(" << op->getName() << ") finds op (bad)";
return false;
@@ -421,6 +422,7 @@
{
UMLAttributeList attributeList;
foreach (UMLObject* listItem , m_List ) {
+ uIgnoreZeroPointer(listItem);
if (listItem->getBaseType() == Uml::ot_Attribute) {
attributeList.append(static_cast<UMLAttribute*>(listItem));
}
@@ -442,6 +444,7 @@
UMLAttributeList atl = getAttributeList();
foreach(UMLAttribute* at, atl )
{
+ uIgnoreZeroPointer(at);
if (! at->getStatic())
{
if (scope == Uml::Visibility::Private)
@@ -476,6 +479,7 @@
UMLAttributeList atl = getAttributeList();
foreach(UMLAttribute* at, atl )
{
+ uIgnoreZeroPointer(at);
if (at->getStatic())
{
if (scope == Uml::Visibility::Private)
@@ -507,6 +511,7 @@
const bool caseSensitive = UMLApp::app()->activeLanguageIsCaseSensitive();
UMLOperationList list;
foreach (UMLObject* obj, m_List) {
+ uIgnoreZeroPointer(obj);
if (obj->getBaseType() != Uml::ot_Operation)
continue;
UMLOperation *op = static_cast<UMLOperation*>(obj);
@@ -552,6 +557,7 @@
UMLClassifierList inheritingConcepts;
Uml::IDType myID = getID();
foreach(UMLClassifier *c , list ) {
+ uIgnoreZeroPointer(c);
if (type == ALL || (!c->isInterface() && type == CLASS)
|| (c->isInterface() && type == INTERFACE)) {
inheritingConcepts.append(c);
@@ -559,6 +565,7 @@
}
foreach (UMLAssociation *a , rlist ) {
+ uIgnoreZeroPointer(a);
if (a->getObjectId(A) != myID)
{
UMLObject* obj = a->getObject(A);
@@ -589,6 +596,7 @@
UMLClassifierList parentConcepts;
Uml::IDType myID = getID();
foreach (UMLClassifier *concept , list ) {
+ uIgnoreZeroPointer(concept);
if (type == ALL || (!concept->isInterface() && type == CLASS)
|| (concept->isInterface() && type == INTERFACE))
parentConcepts.append(concept);
@@ -659,6 +667,7 @@
bool success = UMLPackage::resolveRef();
// Using reentrant iteration is a bare necessity here:
foreach (UMLObject* obj, m_List ) {
+ uIgnoreZeroPointer(obj);
/**** For reference, here is the non-reentrant iteration scheme -
DO NOT USE THIS !
for (UMLObject *obj = m_List.first(); obj; obj = m_List.next())
@@ -763,6 +772,7 @@
UMLAttribute* UMLClassifier::addAttribute(const QString &name, Uml::IDType id /* = Uml::id_None */)
{
foreach (UMLObject* obj, m_List ) {
+ uIgnoreZeroPointer(obj);
if (obj->getBaseType() == Uml::ot_Attribute && obj->getName() == name)
return static_cast<UMLAttribute*>(obj);
}
@@ -806,6 +816,7 @@
bool UMLClassifier::addAttribute(UMLAttribute* att, IDChangeLog* log /* = 0 */,
int position /* = -1 */)
{
+ Q_ASSERT(att);
if (findChildObject(att->getName()) == NULL) {
att->setParent(this);
if (position >= 0 && position < (int)m_List.count()) {
@@ -873,6 +884,7 @@
{
UMLOperationList opl( getOpList() );
foreach(UMLOperation *op , opl ) {
+ uIgnoreZeroPointer(op);
if (op->getAbstract()) {
return true;
}
@@ -900,6 +912,7 @@
{
UMLOperationList ops;
foreach (UMLObject* li, m_List) {
+ uIgnoreZeroPointer(li);
if (li->getBaseType() == ot_Operation) {
ops.append(static_cast<UMLOperation*>(li));
}
@@ -942,7 +955,8 @@
{
UMLClassifierListItemList resultList;
foreach (UMLObject* o, m_List) {
- if (o->getBaseType() == Uml::ot_Association) {
+ uIgnoreZeroPointer(o);
+ if (!o || o->getBaseType() == Uml::ot_Association) {
continue;
}
UMLClassifierListItem *listItem = static_cast<UMLClassifierListItem*>(o);
@@ -1077,6 +1091,7 @@
{
UMLTemplateList templateList;
foreach (UMLObject* listItem, m_List) {
+ uIgnoreZeroPointer(listItem);
if (listItem->getBaseType() == Uml::ot_Template) {
templateList.append(static_cast<UMLTemplate*>(listItem));
}
@@ -1096,6 +1111,7 @@
{
QString buf;
foreach (UMLObject* currentAtt, m_List ) {
+ uIgnoreZeroPointer(currentAtt);
QString txt = currentAtt->getName();
if (txt.isEmpty()) {
txt = "Type-" + QString::number((int) currentAtt->getBaseType());
@@ -1275,6 +1291,7 @@
UMLAssociationList uniAssocListToBeImplemented;
foreach (UMLAssociation *a , associations ) {
+ uIgnoreZeroPointer(a);
if (a->getObjectId(Uml::B) == getID()) {
continue; // we need to be at the A side
}
@@ -1284,6 +1301,7 @@
bool found = false;
//make sure that an attribute with the same name doesn't already exist
foreach (UMLAttribute *at , atl ) {
+ uIgnoreZeroPointer(a);
if (at->getName() == roleNameB) {
found = true;
break;
--- trunk/KDE/kdesdk/umbrello/umbrello/umlcanvasobject.cpp #917127:917128
@@ -69,6 +69,7 @@
UMLObject *o = NULL;
for (UMLObjectListIt oit(m_List); oit.hasNext(); ) {
o = oit.next();
+ uIgnoreZeroPointer(o);
if (o->getBaseType() != Uml::ot_Association)
continue;
UMLAssociation *a = static_cast<UMLAssociation*>(o);
@@ -86,6 +87,7 @@
*/
bool UMLCanvasObject::addAssociationEnd(UMLAssociation* assoc)
{
+ Q_ASSERT(assoc);
// add association only if not already present in list
if(!hasAssociation(assoc))
{
@@ -133,10 +135,10 @@
*/
void UMLCanvasObject::removeAllAssociationEnds()
{
- for (int i = 0; i < m_List.count(); ) {
+ for (int i = 0; i < m_List.count(); i++) {
UMLObject *o = m_List.at(i);
+ uIgnoreZeroPointer(o);
if (o->getBaseType() != Uml::ot_Association) {
- ++i;
continue;
}
UMLAssociation *assoc = static_cast<UMLAssociation*>(o);
@@ -241,6 +243,7 @@
UMLObject *obj = NULL;
for (UMLObjectListIt oit(m_List); oit.hasNext(); ) {
obj = oit.next();
+ uIgnoreZeroPointer(obj);
if (t != Uml::ot_UMLObject && obj->getBaseType() != t)
continue;
if (caseSensitive) {
@@ -266,6 +269,7 @@
UMLObject *o = NULL;
for (UMLObjectListIt oit(m_List); oit.hasNext(); ) {
o = oit.next();
+ uIgnoreZeroPointer(o);
if (o->getID() == id)
return o;
}
@@ -315,6 +319,7 @@
UMLObject *obj = NULL;
for (UMLObjectListIt oit(m_List); oit.hasNext(); ) {
obj = oit.next();
+ uIgnoreZeroPointer(obj);
if (obj->getBaseType() == Uml::ot_Association)
count++;
}
@@ -332,6 +337,7 @@
UMLObject *o = NULL;
for (UMLObjectListIt oit(m_List); oit.hasNext() ; ) {
o = oit.next();
+ uIgnoreZeroPointer(o);
if (o->getBaseType() != Uml::ot_Association)
continue;
UMLAssociation *assoc = static_cast<UMLAssociation*>(o);
@@ -352,6 +358,7 @@
UMLClassifierList list;
UMLAssociationList assocs = getAssociations();
foreach (UMLAssociation* a , assocs ) {
+ uIgnoreZeroPointer(a);
if ((a->getAssocType() != Uml::at_Generalization &&
a->getAssocType() != Uml::at_Realization) ||
a->getObjectId(Uml::A) != getID() )
@@ -378,6 +385,7 @@
UMLClassifierList list;
UMLAssociationList assocs = getAssociations();
foreach (UMLAssociation* a , assocs ) {
+ uIgnoreZeroPointer(a);
if ((a->getAssocType() != Uml::at_Generalization &&
a->getAssocType() != Uml::at_Realization) ||
a->getObjectId(Uml::B) != getID() )
@@ -440,6 +448,7 @@
bool overallSuccess = UMLObject::resolveRef();
for (UMLObjectListIt ait(m_List); ait.hasNext(); ) {
UMLObject *obj = ait.next();
+ uIgnoreZeroPointer(obj);
if (! obj->resolveRef()) {
m_List.removeAll(obj);
overallSuccess = false;
--- trunk/KDE/kdesdk/umbrello/umbrello/umlnamespace.h #917127:917128
@@ -324,6 +324,8 @@
#define uError() kError(8060)
#define uWarning() kWarning(8060)
+#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
+
/**
* Function for comparing tags in XMI files.
*/
More information about the umbrello-devel
mailing list