[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/sdk/kdevplatform/language/duchain
From:       David Nolden <david.nolden.kde () art-master ! de>
Date:       2010-01-16 14:29:04
Message-ID: 1263652144.317292.26200.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1075679 by zwabel:

Add a protection against endless recursion in isPublicBaseClass(..)
BUG: 222334


 M  +21 -4     classdeclaration.cpp  


--- trunk/extragear/sdk/kdevplatform/language/duchain/classdeclaration.cpp \
#1075678:1075679 @@ -82,14 +82,27 @@
   return new ClassDeclaration(*this);
 }
 
-bool ClassDeclaration::isPublicBaseClass( ClassDeclaration* base, const \
KDevelop::TopDUContext* topContext, int* baseConversionLevels ) const { +bool \
isPublicBaseClassInternal( const ClassDeclaration* self, ClassDeclaration* base, \
const KDevelop::TopDUContext* topContext, int* baseConversionLevels, int depth, \
QSet<const ClassDeclaration*>* checked ) { +  
+  if(checked) {
+    if(checked->contains(self))
+      return false;
+    checked->insert(self);
+  }
+  else if(depth > 3)
+  {
+    //Too much depth, to prevent endless recursion, we control the recursion using \
the 'checked' set +    QSet<const ClassDeclaration*> checkedSet;
+    return isPublicBaseClassInternal(self, base, topContext, baseConversionLevels, \
depth, &checkedSet); +  }
+  
   if( baseConversionLevels )
     *baseConversionLevels = 0;
 
-  if( indexedType() == base->indexedType() )
+  if( self->indexedType() == base->indexedType() )
     return true;
 
-  FOREACH_FUNCTION(const BaseClassInstance& b, baseClasses)
+  FOREACH_FUNCTION(const BaseClassInstance& b, self->baseClasses)
   {
     if( baseConversionLevels )
       ++ (*baseConversionLevels);
@@ -98,7 +111,7 @@
       int nextBaseConversion = 0;
       if( StructureType::Ptr c = b.baseClass.type<StructureType>() ) {
         ClassDeclaration* decl = \
                dynamic_cast<ClassDeclaration*>(c->declaration(topContext));
-        if( decl && decl->isPublicBaseClass( base, topContext, &nextBaseConversion ) \
) { +        if( decl && isPublicBaseClassInternal( decl, base, topContext, \
&nextBaseConversion, depth+1, checked ) ) {  if ( baseConversionLevels )
             *baseConversionLevels += nextBaseConversion;
           return true;
@@ -111,6 +124,10 @@
   return false;
 }
 
+bool ClassDeclaration::isPublicBaseClass( ClassDeclaration* base, const \
KDevelop::TopDUContext* topContext, int* baseConversionLevels ) const { +  return \
isPublicBaseClassInternal( this, base, topContext, baseConversionLevels, 0, 0 ); +}
+
 QString ClassDeclaration::toString() const {
   QString ret;
   switch ( classModifier() ) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic