From 19fe2beaa47f342600510e344260942b18a6565c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 8 Aug 2012 20:41:26 -0700 Subject: [PATCH] Bug 299911. Fixed NPE and an unsafe method call. --- .../core/dom/parser/SizeofCalculator.java | 11 ++++++++--- .../dom/parser/cpp/semantics/EvalTypeId.java | 16 +++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 625ec0c2446..cdc024cd703 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** @@ -70,6 +71,8 @@ public class SizeofCalculator { public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_complex_long_double; + private final IASTTranslationUnit ast; + /** * Returns the default instance of sizeof calculator. The default instance is not aware * of the parser configuration and can only calculate sizes that are the same across all @@ -80,6 +83,7 @@ public class SizeofCalculator { } public SizeofCalculator(IASTTranslationUnit ast) { + this.ast = ast; int maxAlignment = 32; Map sizeofMacros = new HashMap(); for (IASTPreprocessorMacroDefinition macro : ast.getBuiltinMacroDefinitions()) { @@ -131,6 +135,7 @@ public class SizeofCalculator { sizeof_complex_double = null; sizeof_long_double = null; sizeof_complex_long_double = null; + ast = null; } /** @@ -246,7 +251,7 @@ public class SizeofCalculator { IField[] fields; if (type instanceof ICPPClassType) { ICPPClassType classType = (ICPPClassType) type; - for (ICPPBase base : classType.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(classType, ast)) { if (base.isVirtual()) return null; // Don't know how to calculate size when there are virtual bases. IBinding baseClass = base.getBaseClass(); @@ -258,14 +263,14 @@ public class SizeofCalculator { size += info.alignment - (size - 1) % info.alignment - 1 + info.size; if (maxAlignment < info.alignment) maxAlignment = info.alignment; - for (ICPPMethod method : classType.getDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, ast)) { if (method.isVirtual()) { // Don't know how to calculate size when there are virtual functions. return null; } } } - fields = classType.getDeclaredFields(); + fields = ClassTypeHelper.getDeclaredFields(classType, ast); } else { fields = type.getFields(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index f17201b2139..41a0fce27aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -147,14 +147,16 @@ public class EvalTypeId extends CPPEvaluation { public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { ICPPEvaluation[] args = fArguments; - for (int i = 0; i < fArguments.length; i++) { - ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (arg != fArguments[i]) { - if (args == fArguments) { - args = new ICPPEvaluation[fArguments.length]; - System.arraycopy(fArguments, 0, args, 0, fArguments.length); + if (fArguments != null) { + for (int i = 0; i < fArguments.length; i++) { + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (arg != fArguments[i]) { + if (args == fArguments) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; } - args[i] = arg; } } IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);