Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-11-04 16:16:04 +0000
committerMarkus Schorn2010-11-04 16:16:04 +0000
commitff18b15fdb9d8afbee738d14dc1313b4c3b8b43e (patch)
tree909a2ce7daa4dd53f215d4ad815904c8cde686cc
parentfdfbe1e62c7fe7e3ecddfa33e22b8efa548a8447 (diff)
downloadorg.eclipse.cdt-ff18b15fdb9d8afbee738d14dc1313b4c3b8b43e.tar.gz
org.eclipse.cdt-ff18b15fdb9d8afbee738d14dc1313b4c3b8b43e.tar.xz
org.eclipse.cdt-ff18b15fdb9d8afbee738d14dc1313b4c3b8b43e.zip
Bug 328380: Improved safeguard against infinite recursion.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java31
1 files changed, 23 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java
index 9052b611563..54ca87d2101 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java
@@ -35,7 +35,7 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
}
public static final int MAX_RESOLUTION_DEPTH = 5;
- public static final int MAX_TYPE_NESTING = 100;
+ public static final int MAX_TYPE_NESTING = 60;
private IType type;
private int fResolutionDepth;
@@ -53,6 +53,10 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
*/
public IType getType() {
+ return getType(MAX_TYPE_NESTING);
+ }
+
+ private IType getType(int maxDepth) {
if (type == null) {
try {
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
@@ -61,13 +65,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
type= specializeType(getTypedef().getType());
// A typedef pointing to itself is a sure recipe for an infinite loop -- replace
// with a problem binding.
- IType checkType= type;
- for (int i = 0; checkType instanceof ITypeContainer; i++) {
- if (this.equals(checkType) || i == MAX_TYPE_NESTING) {
- type = new RecursionResolvingBinding(getDefinition(), getNameCharArray());
- break;
- }
- checkType= ((ITypeContainer) checkType).getType();
+ if (!verifyType(type, maxDepth)) {
+ type = new RecursionResolvingBinding(getDefinition(), getNameCharArray());
}
}
} finally {
@@ -77,6 +76,22 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
return type;
}
+ private boolean verifyType(IType type, int maxTypeNesting) {
+ for (;;) {
+ if (--maxTypeNesting < 0)
+ return false;
+ if (equals(type))
+ return false;
+ if (type instanceof CPPTypedefSpecialization) {
+ type= ((CPPTypedefSpecialization) type).getType(maxTypeNesting);
+ } else if (type instanceof ITypeContainer) {
+ type= ((ITypeContainer) type).getType();
+ } else {
+ return true;
+ }
+ }
+ }
+
public int incResolutionDepth(int increment) {
fResolutionDepth += increment;
return fResolutionDepth;

Back to the top