1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 10:15:39 +02:00

Bug 545751 - NPE in EvalTypeId.getValue()

Change-Id: Ia11dc1a8af6633ffe54ca927c68bf8dc837604a0
This commit is contained in:
Nathan Ridge 2019-03-26 02:07:31 -04:00
parent f2635eed74
commit 2cdbc5ebb6

View file

@ -42,6 +42,7 @@ import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue; import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
@ -195,7 +196,9 @@ public class EvalTypeId extends CPPDependentEvaluation {
// Cast signed integer to unsigned. // Cast signed integer to unsigned.
Long val = argVal.numberValue().longValue(); Long val = argVal.numberValue().longValue();
if (val < 0 && inputType instanceof ICPPBasicType && ((ICPPBasicType) inputType).isUnsigned()) { if (val < 0 && inputType instanceof ICPPBasicType && ((ICPPBasicType) inputType).isUnsigned()) {
long sizeof = SizeofCalculator.getSizeAndAlignment(inputType).size; SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(inputType);
if (sizeAndAlignment != null) {
long sizeof = sizeAndAlignment.size;
if (sizeof > 4) { if (sizeof > 4) {
// Java's "long" can't represent the full range of an 64-bit unsigned integer // Java's "long" can't represent the full range of an 64-bit unsigned integer
// in C++. // in C++.
@ -206,6 +209,7 @@ public class EvalTypeId extends CPPDependentEvaluation {
return IntegralValue.create(val); return IntegralValue.create(val);
} }
} }
}
return argVal; return argVal;
} }
return IntegralValue.UNKNOWN; return IntegralValue.UNKNOWN;