1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

Protect against NPE in case "declarators" is null

Change-Id: Iab76315980cab8f2070cdf3ba853871b0eecf74c
Signed-off-by: Jesper Eskilson <jesper.eskilson@iar.com>
This commit is contained in:
Jesper Eskilson 2017-03-24 10:56:15 +01:00 committed by Gerrit Code Review @ Eclipse.org
parent 548d5e19e1
commit 611c89cd36

View file

@ -23,7 +23,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecSimpleDeclarat
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IASTSimpleDeclaration, ICPPExecutionOwner { public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner
implements IASTSimpleDeclaration, ICPPExecutionOwner {
private IASTDeclarator[] declarators; private IASTDeclarator[] declarators;
private int declaratorsPos = -1; private int declaratorsPos = -1;
private IASTDeclSpecifier declSpecifier; private IASTDeclSpecifier declSpecifier;
@ -74,7 +75,8 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
} }
/** /**
* @param declSpecifier The declSpecifier to set. * @param declSpecifier
* The declSpecifier to set.
*/ */
@Override @Override
public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) {
@ -90,14 +92,19 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
public boolean accept(ASTVisitor action) { public boolean accept(ASTVisitor action) {
if (action.shouldVisitDeclarations) { if (action.shouldVisitDeclarations) {
switch (action.visit(this)) { switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_ABORT:
case ASTVisitor.PROCESS_SKIP: return true; return false;
default: break; case ASTVisitor.PROCESS_SKIP:
return true;
default:
break;
} }
} }
if (!acceptByAttributeSpecifiers(action)) return false; if (!acceptByAttributeSpecifiers(action))
if (declSpecifier != null && !declSpecifier.accept(action)) return false; return false;
if (declSpecifier != null && !declSpecifier.accept(action))
return false;
IASTDeclarator[] dtors = getDeclarators(); IASTDeclarator[] dtors = getDeclarators();
for (int i = 0; i < dtors.length; i++) { for (int i = 0; i < dtors.length; i++) {
if (!dtors[i].accept(action)) if (!dtors[i].accept(action))
@ -106,9 +113,12 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
if (action.shouldVisitDeclarations) { if (action.shouldVisitDeclarations) {
switch (action.leave(this)) { switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_ABORT:
case ASTVisitor.PROCESS_SKIP: return true; return false;
default: break; case ASTVisitor.PROCESS_SKIP:
return true;
default:
break;
} }
} }
return true; return true;
@ -130,6 +140,7 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
@Override @Override
public ICPPExecution getExecution() { public ICPPExecution getExecution() {
IASTDeclarator[] declarators = getDeclarators();
ICPPExecution[] declaratorExecutions = new ICPPExecution[declarators.length]; ICPPExecution[] declaratorExecutions = new ICPPExecution[declarators.length];
for (int i = 0; i < declarators.length; ++i) { for (int i = 0; i < declarators.length; ++i) {
declaratorExecutions[i] = ((ICPPExecutionOwner) declarators[i]).getExecution(); declaratorExecutions[i] = ((ICPPExecutionOwner) declarators[i]).getExecution();