1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +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
*/
public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IASTSimpleDeclaration, ICPPExecutionOwner {
public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner
implements IASTSimpleDeclaration, ICPPExecutionOwner {
private IASTDeclarator[] declarators;
private int declaratorsPos = -1;
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
public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) {
@ -90,14 +92,19 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
public boolean accept(ASTVisitor action) {
if (action.shouldVisitDeclarations) {
switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP: return true;
default: break;
case ASTVisitor.PROCESS_ABORT:
return false;
case ASTVisitor.PROCESS_SKIP:
return true;
default:
break;
}
}
if (!acceptByAttributeSpecifiers(action)) return false;
if (declSpecifier != null && !declSpecifier.accept(action)) return false;
if (!acceptByAttributeSpecifiers(action))
return false;
if (declSpecifier != null && !declSpecifier.accept(action))
return false;
IASTDeclarator[] dtors = getDeclarators();
for (int i = 0; i < dtors.length; i++) {
if (!dtors[i].accept(action))
@ -106,9 +113,12 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
if (action.shouldVisitDeclarations) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP: return true;
default: break;
case ASTVisitor.PROCESS_ABORT:
return false;
case ASTVisitor.PROCESS_SKIP:
return true;
default:
break;
}
}
return true;
@ -130,6 +140,7 @@ public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IAS
@Override
public ICPPExecution getExecution() {
IASTDeclarator[] declarators = getDeclarators();
ICPPExecution[] declaratorExecutions = new ICPPExecution[declarators.length];
for (int i = 0; i < declarators.length; ++i) {
declaratorExecutions[i] = ((ICPPExecutionOwner) declarators[i]).getExecution();