1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 00:35:49 +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.IntegralValue;
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.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
@ -195,15 +196,18 @@ public class EvalTypeId extends CPPDependentEvaluation {
// Cast signed integer to unsigned.
Long val = argVal.numberValue().longValue();
if (val < 0 && inputType instanceof ICPPBasicType && ((ICPPBasicType) inputType).isUnsigned()) {
long sizeof = SizeofCalculator.getSizeAndAlignment(inputType).size;
if (sizeof > 4) {
// Java's "long" can't represent the full range of an 64-bit unsigned integer
// in C++.
sizeof = 4;
SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(inputType);
if (sizeAndAlignment != null) {
long sizeof = sizeAndAlignment.size;
if (sizeof > 4) {
// Java's "long" can't represent the full range of an 64-bit unsigned integer
// in C++.
sizeof = 4;
}
long range = (1L << (sizeof * 8 - 1));
val += range;
return IntegralValue.create(val);
}
long range = (1L << (sizeof * 8 - 1));
val += range;
return IntegralValue.create(val);
}
}
return argVal;