mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 03:35:37 +02:00
Bug 491834 - StackOverflowError in HeuristicResolver
Change-Id: I8aaf80e66d6d7bd999482450c506f7160bd276fd
This commit is contained in:
parent
fc07efa909
commit
6be5a7fbe0
1 changed files with 86 additions and 64 deletions
|
@ -96,6 +96,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
|
||||||
* implementing more advanced heuristics that could deal with this.
|
* implementing more advanced heuristics that could deal with this.
|
||||||
*/
|
*/
|
||||||
public class HeuristicResolver {
|
public class HeuristicResolver {
|
||||||
|
// Infrastructure to protect against infinite recursion in heuristic resolution.
|
||||||
|
private static final int RESOLUTION_DEPTH_LIMIT = 32;
|
||||||
|
private static final ThreadLocal<Integer> fResolutionDepth = new ThreadLocal<Integer>() {
|
||||||
|
@Override
|
||||||
|
protected Integer initialValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a dependent type, heuristically tries to find a concrete scope (i.e. not an unknown scope)
|
* Given a dependent type, heuristically tries to find a concrete scope (i.e. not an unknown scope)
|
||||||
* for it.
|
* for it.
|
||||||
|
@ -342,9 +351,18 @@ public class HeuristicResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for resolveUnknownType() which does one round of resolution.
|
* Helper function for {@link #resolveUnknownType} which does one round of resolution.
|
||||||
*/
|
*/
|
||||||
private static IType resolveUnknownTypeOnce(ICPPUnknownType type, IASTNode point) {
|
private static IType resolveUnknownTypeOnce(ICPPUnknownType type, IASTNode point) {
|
||||||
|
// Guard against infinite recursion.
|
||||||
|
int resolutionDepth = fResolutionDepth.get();
|
||||||
|
if (resolutionDepth > RESOLUTION_DEPTH_LIMIT) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
// Increment the resolution depth for the duration of this call.
|
||||||
|
fResolutionDepth.set(resolutionDepth + 1);
|
||||||
|
|
||||||
|
try {
|
||||||
if (type instanceof ICPPDeferredClassInstance) {
|
if (type instanceof ICPPDeferredClassInstance) {
|
||||||
ICPPDeferredClassInstance deferredInstance = (ICPPDeferredClassInstance) type;
|
ICPPDeferredClassInstance deferredInstance = (ICPPDeferredClassInstance) type;
|
||||||
return deferredInstance.getClassTemplate();
|
return deferredInstance.getClassTemplate();
|
||||||
|
@ -415,6 +433,10 @@ public class HeuristicResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
// Restore original resolution depth.
|
||||||
|
fResolutionDepth.set(resolutionDepth);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue