1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

More robust infinite recursion protection in CompositeValue.create

Change-Id: Ic0303db73c19651d341f84748b87efc9868defc4
This commit is contained in:
Sergey Prigogin 2017-03-01 17:41:12 -08:00
parent 5a71bf21d8
commit f311c6f050

View file

@ -8,8 +8,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
@ -157,12 +157,16 @@ public final class CompositeValue implements IValue {
} }
// The set of class types for which composite value creation is in progress on each thread. // The set of class types for which composite value creation is in progress on each thread.
// Used to guard against infinite recursion due to a class (invalidly) aggregating itself. // Used to guard against infinite recursion due to a class (illegally) aggregating itself.
private static final ThreadLocal<Set<ICPPClassType>> fCreateInProgress = private static final ThreadLocal<Set<ICPPClassType>> fCreateInProgress =
new ThreadLocal<Set<ICPPClassType>>() { new ThreadLocal<Set<ICPPClassType>>() {
@Override @Override
protected Set<ICPPClassType> initialValue() { protected Set<ICPPClassType> initialValue() {
return new HashSet<>(); return new TreeSet<>((type1, type2) -> {
if (type1.isSameType(type2))
return 0;
return ASTTypeUtil.getType(type1, true).compareTo(ASTTypeUtil.getType(type2, true));
});
} }
}; };
@ -185,10 +189,11 @@ public final class CompositeValue implements IValue {
if (!recursionProtectionSet.add(classType)) { if (!recursionProtectionSet.add(classType)) {
return new CompositeValue(null, ICPPEvaluation.EMPTY_ARRAY); return new CompositeValue(null, ICPPEvaluation.EMPTY_ARRAY);
} }
if (sDEBUG && nestingLevel > 0) {
System.out.println("CompositeValue.create(" + ASTTypeUtil.getType(classType) + ", " + nestingLevel + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
try { try {
if (sDEBUG && nestingLevel > 0) {
System.out.println("CompositeValue.create(" + ASTTypeUtil.getType(classType) + ", " + nestingLevel + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
System.out.flush();
}
ActivationRecord record = new ActivationRecord(); ActivationRecord record = new ActivationRecord();
ICPPEvaluation[] values = new ICPPEvaluation[ClassTypeHelper.getFields(classType, point).length]; ICPPEvaluation[] values = new ICPPEvaluation[ClassTypeHelper.getFields(classType, point).length];