Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Vogt2019-04-30 02:26:20 -0400
committerHannes Vogt2019-05-20 14:49:26 -0400
commit1cd0e1df35696e143697533ad3b1b35171d0670a (patch)
tree966419534ded56c3b304ec0c08abbcd971f7ac43 /core/org.eclipse.cdt.core
parentf938b4d08e59c67309cb0fac1e2bbc8dc1acfa90 (diff)
downloadorg.eclipse.cdt-1cd0e1df35696e143697533ad3b1b35171d0670a.tar.gz
org.eclipse.cdt-1cd0e1df35696e143697533ad3b1b35171d0670a.tar.xz
org.eclipse.cdt-1cd0e1df35696e143697533ad3b1b35171d0670a.zip
Bug 546805 - Infinite recursion in self-aggregation
Protects for infinite recursion in case the type (illegally) aggregates itself. Change-Id: I2e70f85a73b3d2ed6fec432fa2f768f2bcf8d1bf Signed-off-by: Hannes Vogt <hannes@havogt.de>
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
index 9397d19ee4..35b839e671 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
@@ -128,7 +128,7 @@ class AggregateInitialization {
* checkElement() for each element of an array or each field of a class aggregate.
*/
private Cost checkInitializationOfElements(IType type, Cost worstCost) throws DOMException {
- if (type instanceof ICPPClassType && TypeTraits.isAggregateClass((ICPPClassType) type)) {
+ if (type instanceof ICPPClassType && isAggregate(type)) {
ICPPField[] fields = getFieldsForAggregateInitialization((ICPPClassType) type);
for (ICPPField field : fields) {
Cost cost = checkElement(field.getType(), field.getInitialValue(), worstCost);
@@ -180,8 +180,25 @@ class AggregateInitialization {
}
private static boolean isAggregate(IType type) {
- return (type instanceof ICPPClassType && TypeTraits.isAggregateClass((ICPPClassType) type))
- || type instanceof IArrayType;
+ return (type instanceof ICPPClassType && TypeTraits.isAggregateClass((ICPPClassType) type)
+ && !isSelfAggregate((ICPPClassType) type, null)) || type instanceof IArrayType;
+ }
+
+ // Check if a class is (illegally) aggregating itself
+ private static boolean isSelfAggregate(ICPPClassType type, ICPPClassType subType) {
+ if (type.isSameType(subType))
+ return true;
+
+ if (subType == null)
+ subType = type;
+ for (ICPPField field : subType.getDeclaredFields()) {
+ IType fieldType = field.getType();
+ if (fieldType instanceof ICPPClassType && TypeTraits.isAggregateClass((ICPPClassType) fieldType)) {
+ if (isSelfAggregate(type, (ICPPClassType) fieldType))
+ return true;
+ }
+ }
+ return false;
}
/**

Back to the top