From 08293b3f584834b4cc7e911e42f9779500fc61b6 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sun, 17 Nov 2013 03:12:47 -0500 Subject: [PATCH] Bug 421900 - NPE in StatementHasNoEffectChecker.usesOverloadOperator() Change-Id: I9099f3600cfdac492784087ef5993b353111eab8 Signed-off-by: Nathan Ridge Reviewed-on: https://git.eclipse.org/r/18468 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../checkers/StatementHasNoEffectChecker.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java index c3f140e51ab..91831ed46ce 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java @@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBasicType; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; /** @@ -169,9 +168,13 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) expr).getImplicitNames(); if (implicitNames.length > 0) return true; - IType operand1Type = expr.getOperand1().getExpressionType(); - IType operand2Type = expr.getOperand2().getExpressionType(); - if (!(operand1Type instanceof IBasicType && operand2Type instanceof IBasicType)) { + IASTExpression operand1 = expr.getOperand1(); + IASTExpression operand2 = expr.getOperand2(); + // This shouldn't happen, but if it does, it's better to have a + // false negative than a false positive warning. + if (operand1 == null || operand2 == null) + return true; + if (!(operand1.getExpressionType() instanceof IBasicType && operand2.getExpressionType() instanceof IBasicType)) { return true; // must be overloaded but parser could not find it } } @@ -183,8 +186,12 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) expr).getImplicitNames(); if (implicitNames.length > 0) return true; - IType operandType = expr.getOperand().getExpressionType(); - if (!(operandType instanceof IBasicType)) { + IASTExpression operand = expr.getOperand(); + // This shouldn't happen, but if it does, it's better to have a + // false negative than a false positive warning. + if (operand == null) + return true; + if (!(operand.getExpressionType() instanceof IBasicType)) { return true; // must be overloaded but parser could not find it } }