Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-09 15:42:09 +0000
committerMarkus Schorn2008-04-09 15:42:09 +0000
commit5dacb8918f0c27e06de79a029cc3396c0ab9cad9 (patch)
tree49424eb52d2788ec64685a6062a015f52b7ab86f /core/org.eclipse.cdt.core
parentae39bd607b0076b0e5a9073cac7dc4468293addd (diff)
downloadorg.eclipse.cdt-5dacb8918f0c27e06de79a029cc3396c0ab9cad9.tar.gz
org.eclipse.cdt-5dacb8918f0c27e06de79a029cc3396c0ab9cad9.tar.xz
org.eclipse.cdt-5dacb8918f0c27e06de79a029cc3396c0ab9cad9.zip
Fixes potential NPEs.
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java1
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java30
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java34
3 files changed, 34 insertions, 31 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index c8da1fc5084..c2a5370f662 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -1141,6 +1141,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} else {
IToken la = LA(1);
throwBacktrack(la.getOffset(), la.getLength());
+ return null; // line is never reached, hint for the parser
}
IASTExpression initialValue = null;
if (LT(1) == IToken.tASSIGN) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 77171332eba..d3ac738eb7f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -1256,13 +1256,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
try {
lookAheadForDeclarator(flags);
} catch (FoundDeclaratorException e) {
- ICASTSimpleDeclSpecifier declSpec = null;
- if (typeofExpression != null) {
- declSpec = createGCCSimpleTypeSpecifier();
- ((IGCCASTSimpleDeclSpecifier) declSpec).setTypeofExpression(typeofExpression);
- } else {
- declSpec = createSimpleTypeSpecifier();
- }
+ ICASTSimpleDeclSpecifier declSpec= createSimpleTypeSpecifier();
declSpec.setConst(isConst);
declSpec.setRestrict(isRestrict);
@@ -1276,12 +1270,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setUnsigned(isUnsigned);
declSpec.setSigned(isSigned);
declSpec.setShort(isShort);
- if( typeofExpression != null && last == null ){
- ((ASTNode)declSpec).setOffsetAndLength( (ASTNode)typeofExpression );
- } else {
- ((ASTNode) declSpec).setOffsetAndLength(startingOffset,
- (last != null) ? last.getEndOffset() - startingOffset : 0);
- }
+ ((ASTNode) declSpec).setOffsetAndLength(startingOffset,
+ (last != null) ? last.getEndOffset() - startingOffset : 0);
e.declSpec = declSpec;
throw e;
}
@@ -1385,7 +1375,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setInline(isInline);
declSpec.setStorageClass(storageClass);
- ((ASTNode) declSpec).setOffsetAndLength(startingOffset, last.getEndOffset() - startingOffset);
+ if (last != null) {
+ ((ASTNode) declSpec).setOffsetAndLength(startingOffset, last.getEndOffset() - startingOffset);
+ }
IASTName name = createName(identifier);
declSpec.setName(name);
return declSpec;
@@ -1462,6 +1454,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
break;
default:
throwBacktrack(mark.getOffset(), mark.getLength());
+ return null; // line never reached, hint for the parser.
}
// if __attribute__ or __declspec occurs after struct/union/class and before the identifier
@@ -1636,13 +1629,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
switch (LT(1)) {
case IToken.tCOMMA:
last = consume();
- seenParameter = false;
+ parmNames[i] = createName(identifier());
+ seenParameter = true;
+ break;
case IToken.tIDENTIFIER:
if (seenParameter)
throwBacktrack(startingOffset, last.getEndOffset() - startingOffset);
parmNames[i] = createName(identifier());
-
seenParameter = true;
break;
case IToken.tRPAREN:
@@ -1694,8 +1688,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
parmDeclarations[i] = declaration;
} else {
parmDeclarations[i] = createKnRCProblemDeclaration(
- ((ASTNode) declaration).getLength(),
- ((ASTNode) declaration).getOffset());
+ ((ASTNode) decl).getLength(),
+ ((ASTNode) decl).getOffset());
}
} catch (BacktrackException b) {
parmDeclarations[i] = createKnRCProblemDeclaration(
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 2c81fb3a9c3..c5d39af6f23 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -1414,7 +1414,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch (n.length) {
case 0:
throwBacktrack(LA(1));
- break;
+ return null; // line is never reached, hint for the parser
case 1:
if (n[0] instanceof IASTTypeId) {
firstExpression = buildTypeIdExpression(
@@ -1424,6 +1424,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
firstExpression = buildUnaryExpression(
ICPPASTUnaryExpression.op_typeid,
(IASTExpression) n[0], so, lastOffset);
+ } else {
+ throwBacktrack(LA(1));
+ return null; // line is never reached, hint for the parser
}
break;
case 2:
@@ -1439,6 +1442,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
((ASTNode) ambExpr).setOffsetAndLength((ASTNode) e2);
firstExpression = ambExpr;
break;
+
+ default:
+ assert false;
+ throwBacktrack(LA(1));
+ return null; // line is never reached, hint for the parser
}
break;
@@ -3056,21 +3064,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
catch( FoundDeclaratorException fde )
{
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
- if (isLongLong || typeofExpression != null) {
+ if (isLongLong) {
simpleDeclSpec = createGPPSimpleDeclSpecifier();
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec).setLongLong(isLongLong);
- if (typeofExpression != null) {
- ((IGPPASTSimpleDeclSpecifier) simpleDeclSpec).setTypeofExpression(typeofExpression);
- }
} else
simpleDeclSpec = createSimpleDeclSpecifier();
- if( last == null && typeofExpression != null ){
- ((ASTNode) simpleDeclSpec).setOffsetAndLength((ASTNode) typeofExpression);
- } else {
- int l = last != null ? last.getEndOffset() - firstToken.getOffset() : 0;
- ((ASTNode) simpleDeclSpec).setOffsetAndLength(firstToken.getOffset(), l);
- }
+ int l = last != null ? last.getEndOffset() - firstToken.getOffset() : 0;
+ ((ASTNode) simpleDeclSpec).setOffsetAndLength(firstToken.getOffset(), l);
+
simpleDeclSpec.setConst(isConst);
simpleDeclSpec.setVolatile(isVolatile);
if (simpleDeclSpec instanceof IGPPASTDeclSpecifier)
@@ -3203,7 +3205,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
nameSpec.setStorageClass(storageClass);
nameSpec.setVirtual(isVirtual);
nameSpec.setExplicit(isExplicit);
- ((ASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset);
+ if (last != null) {
+ ((ASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset);
+ }
+ else {
+ ((ASTNode) nameSpec).setOffsetAndLength(startOffset, duple.getLastToken().getEndOffset() - startOffset);
+ }
return nameSpec;
}
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
@@ -3830,7 +3837,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
backup(mark);
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
}
- int endOffset = (mark != null) ? mark.getEndOffset() : 0;
+ int endOffset= mark.getEndOffset();
backup(mark);
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
@@ -3869,6 +3876,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
break;
default:
throwBacktrack(mark.getOffset(), mark.getLength());
+ return null; // line is never reached, hint for the parser
}
IASTName name = null;

Back to the top