1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Bug 534098 - NPE in VariableHelpers.createType()

Change-Id: I0b287d31dba8075d8e99f74d6815d3018c985bc7
This commit is contained in:
Nathan Ridge 2018-04-27 02:49:51 -04:00
parent ac0e24da56
commit d7c4642ab8
3 changed files with 18 additions and 5 deletions

View file

@ -12681,4 +12681,16 @@ public class AST2CPPTests extends AST2CPPTestBase {
helper.assertVariableType("v_b", CPPBasicType.UNSIGNED_LONG_LONG); helper.assertVariableType("v_b", CPPBasicType.UNSIGNED_LONG_LONG);
helper.assertVariableType("v_c", CPPBasicType.LONG_LONG); helper.assertVariableType("v_c", CPPBasicType.LONG_LONG);
} }
// extern void *List[];
// extern void *List[];
// void *List[] = { 0 };
// unsigned int ListSize = sizeof(List)/sizeof(List[0]);
public void testMultipleExternDecls_534098() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
IVariable var = helper.assertNonProblem("ListSize");
// Trigger initial value computation, test that it
// does not throw an exception.
var.getInitialValue();
}
} }

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -57,7 +58,7 @@ public class CPPBuiltinVariable extends CPPVariable {
* Returns null. * Returns null.
*/ */
@Override @Override
public IASTNode[] getDeclarations() { public IASTName[] getDeclarations() {
return null; return null;
} }

View file

@ -56,7 +56,7 @@ import org.eclipse.core.runtime.PlatformObject;
public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredVariable { public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredVariable {
private IASTName fDefinition; private IASTName fDefinition;
private IASTName fDeclarations[]; private IASTName fDeclarations[]; // Allowed to have trailing nulls. Users must check or trim!
private IType fType; private IType fType;
private IValue fInitialValue = IntegralValue.NOT_INITIALIZED; private IValue fInitialValue = IntegralValue.NOT_INITIALIZED;
private boolean fAllResolved; private boolean fAllResolved;
@ -119,8 +119,8 @@ public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredV
} }
@Override @Override
public IASTNode[] getDeclarations() { public IASTName[] getDeclarations() {
return fDeclarations; return fDeclarations == null ? null : ArrayUtil.trim(fDeclarations);
} }
@Override @Override
@ -136,7 +136,7 @@ public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredV
boolean allResolved = fAllResolved; boolean allResolved = fAllResolved;
fAllResolved = true; fAllResolved = true;
fType = VariableHelpers.createType(this, fDefinition, fDeclarations, allResolved); fType = VariableHelpers.createType(this, fDefinition, getDeclarations(), allResolved);
return fType; return fType;
} }