Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2019-06-04 22:29:55 -0400
committerNathan Ridge2019-06-21 14:44:18 -0400
commit141142dcabbdd373169c1ea1735caf81f0c98b65 (patch)
treeb1ef6baef691ac86a6ce2408487292b057a8e9fc /core/org.eclipse.cdt.core
parent84e2470069f997e976bd879c2ec526fd8773bce5 (diff)
downloadorg.eclipse.cdt-141142dcabbdd373169c1ea1735caf81f0c98b65.tar.gz
org.eclipse.cdt-141142dcabbdd373169c1ea1735caf81f0c98b65.tar.xz
org.eclipse.cdt-141142dcabbdd373169c1ea1735caf81f0c98b65.zip
Bug 547763 - Consistently handle IArrayType.getSize() returning a null IValue
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.java36
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java2
2 files changed, 22 insertions, 16 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 35b839e671..71790051d2 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
@@ -74,12 +74,14 @@ class AggregateInitialization {
if (initFromStringLiteral(nestedType, initializer)) {
// [dcl.init.string]
fIndex++;
- Number sizeOfCharArrayNumber = getArraySize(nestedType);
+ // nestedType is guaranteed to be an IArrayType if initFromStringLiteral() returns true
+ Number sizeOfCharArrayNumber = getArraySize((IArrayType) nestedType);
long sizeofCharArray = 0; // will error in case we cannot determine the size
if (sizeOfCharArrayNumber != null) {
sizeofCharArray = sizeOfCharArrayNumber.longValue();
}
- Number sizeofStringLiteralNumber = getArraySize(initializer.getType());
+ // so is initializer.getType()
+ Number sizeofStringLiteralNumber = getArraySize((IArrayType) initializer.getType());
long sizeofStringLiteral = Long.MAX_VALUE; // will error in case we cannot determine the size
if (sizeofStringLiteralNumber != null) {
sizeofStringLiteral = sizeofStringLiteralNumber.longValue();
@@ -140,16 +142,20 @@ class AggregateInitialization {
}
} else if (type instanceof IArrayType) {
IArrayType arrayType = (IArrayType) type;
- Number arraySize = arrayType.getSize().numberValue();
- if (arraySize != null)
- for (long i = 0; i < arraySize.longValue(); i++) {
- Cost cost = checkElement(arrayType.getType(), null, worstCost);
- if (!cost.converts())
- return cost;
- if (cost.compareTo(worstCost) > 0) {
- worstCost = cost;
+ IValue sizeVal = arrayType.getSize();
+ if (sizeVal != null) {
+ Number arraySize = sizeVal.numberValue();
+ if (arraySize != null) {
+ for (long i = 0; i < arraySize.longValue(); i++) {
+ Cost cost = checkElement(arrayType.getType(), null, worstCost);
+ if (!cost.converts())
+ return cost;
+ if (cost.compareTo(worstCost) > 0) {
+ worstCost = cost;
+ }
}
}
+ }
}
return worstCost;
}
@@ -262,12 +268,10 @@ class AggregateInitialization {
return isCharArray(target) && fromStringLiteral(initializer);
}
- private static Number getArraySize(IType type) {
- if (((IArrayType) type).getSize() != null) {
- IValue size = ((IArrayType) type).getSize();
- if (size.numberValue() != null) {
- return ((IArrayType) type).getSize().numberValue();
- }
+ private static Number getArraySize(IArrayType type) {
+ IValue size = type.getSize();
+ if (size != null) {
+ return size.numberValue();
}
return null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index 5d96ed989a..07e27e0a23 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -1287,6 +1287,8 @@ public class CPPTemplates {
}
static int determinePackSize(IValue value, ICPPTemplateParameterMap tpMap) {
+ if (value == null)
+ return PACK_SIZE_NOT_FOUND;
ICPPEvaluation eval = value.getEvaluation();
if (eval == null)
return PACK_SIZE_NOT_FOUND;

Back to the top