1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +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,15 +196,18 @@ 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 (sizeof > 4) { if (sizeAndAlignment != null) {
// Java's "long" can't represent the full range of an 64-bit unsigned integer long sizeof = sizeAndAlignment.size;
// in C++. if (sizeof > 4) {
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; return argVal;