JS: fixup double reporting of alerts

This commit is contained in:
Esben Sparre Andreasen
2018-10-31 09:33:49 +01:00
parent f440c9221a
commit 7d4cf49545

View File

@@ -73,6 +73,19 @@ predicate isConstantBooleanReturnValue(Expr e) {
isConstantBooleanReturnValue(e.(LogNotExpr).getOperand())
}
/**
* Holds if `e` is a defensive expression with a fixed outcome.
*/
predicate isConstantDefensive(Expr e) {
exists(Expr defensive |
defensive = e or
// traverse negations
defensive.(LogNotExpr).getOperand+() = e
|
exists(defensive.flow().(DefensiveExpression).getTheTestResult())
)
}
/**
* Holds if `e` is an expression that should not be flagged as a useless condition.
*
@@ -87,7 +100,7 @@ predicate isConstantBooleanReturnValue(Expr e) {
predicate whitelist(Expr e) {
isConstant(e) or
isConstant(e.(LogNotExpr).getOperand()) or
exists (e.flow().(DefensiveExpression).getTheTestResult()) or
isConstantDefensive(e) or // flagged by js/useless-defensive-code
isInitialParameterUse(e) or
isConstantBooleanReturnValue(e)
}