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

List:       kde-commits
Subject:    [kdevelop/4.5] languages/cpp/cppduchain: Fix endless recursion in setSpecializedFrom
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2013-07-31 22:29:13
Message-ID: E1V4etN-0007Ia-4c () scm ! kde ! org
[Download RAW message or body]

Git commit b45c87bc010af54bd2d722ca487f0d2311640e74 by Andreas Pakulat.
Committed on 31/07/2013 at 10:50.
Pushed by apaku into branch '4.5'.

Fix endless recursion in setSpecializedFrom

This could be triggered by having the exactly same specialization occur
twice in a single file. setSpecializedFrom would end up calling itself
with the same TemplateDeclaration over and over again.

Adding another recursion counter in the same way that other places already
have one fixes the problem. Unfortunately I wasn't able to generate a test
that exhibits the recursion problem.

M  +25   -1    languages/cpp/cppduchain/templatedeclaration.cpp

http://commits.kde.org/kdevelop/b45c87bc010af54bd2d722ca487f0d2311640e74

diff --git a/languages/cpp/cppduchain/templatedeclaration.cpp \
b/languages/cpp/cppduchain/templatedeclaration.cpp index 321a2dc..0a2283b 100644
--- a/languages/cpp/cppduchain/templatedeclaration.cpp
+++ b/languages/cpp/cppduchain/templatedeclaration.cpp
@@ -160,6 +160,7 @@ struct ThreadLocalData {
   uint delayedDepth;
   // recursion counter for alias type resolution
   uint aliasDepth;
+  uint specializedFromDepth;
 };
 
 #if (QT_VERSION >= 0x040801)
@@ -374,7 +375,30 @@ TemplateDeclaration* TemplateDeclaration::instantiatedFrom() \
const {  }
 
 void TemplateDeclaration::setSpecializedFrom(TemplateDeclaration* other) {
-  
+  ThreadLocalData& data = threadDataLocal();
+  PushValue<uint> safety(data.specializedFromDepth, data.specializedFromDepth+1);
+  if(data.specializedFromDepth > 30) {
+    QString withVal = "other";
+    if( other ) {
+      if( other->instantiatedFrom() ) {
+        withVal += ".instantiatedFrom() == " + \
other->instantiatedFrom()->id(true).qualifiedIdentifier().toString(); +      } else \
if( other->specializedFrom().data() ) { +        withVal += ".specialiedFrom().data() \
== " + other->specializedFrom().data()->identifier().toString(); +      } else {
+        withVal += ".specializedFrom().data() == null && other.instantiatedFrom() == \
null"; +      }
+    } else {
+      withVal = " == null";
+    }
+    kWarning()
+        << "depth-limit reached while setting specializedFrom"
+        << (specializedFrom().data()
+            ? specializedFrom().data()->identifier().toString()
+            : "this specializedFrom is null")
+        << "with" << withVal;
+    return;
+  }
+
   if(other && other->instantiatedFrom()) {
     setSpecializedFrom(other->instantiatedFrom());
     return;


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

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