mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Nullness library: recognise switches with null checks
This commit is contained in:
@@ -1542,6 +1542,11 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
|
||||
exists(YieldStmt yield | yield.getTarget() = this and result = yield.getValue())
|
||||
}
|
||||
|
||||
/** Holds if this switch has a case handling a null literal. */
|
||||
predicate hasNullCase() {
|
||||
this.getAConstCase().getValue(_) instanceof NullLiteral
|
||||
}
|
||||
|
||||
/** Gets a printable representation of this expression. */
|
||||
override string toString() { result = "switch (...)" }
|
||||
|
||||
|
||||
@@ -409,6 +409,11 @@ class SwitchStmt extends Stmt, @switchstmt {
|
||||
/** Gets the expression of this `switch` statement. */
|
||||
Expr getExpr() { result.getParent() = this }
|
||||
|
||||
/** Holds if this switch has a case handling a null literal. */
|
||||
predicate hasNullCase() {
|
||||
this.getAConstCase().getValue(_) instanceof NullLiteral
|
||||
}
|
||||
|
||||
override string pp() { result = "switch (...)" }
|
||||
|
||||
override string toString() { result = "switch (...)" }
|
||||
|
||||
@@ -100,9 +100,9 @@ predicate dereference(Expr e) {
|
||||
or
|
||||
exists(SynchronizedStmt synch | synch.getExpr() = e)
|
||||
or
|
||||
exists(SwitchStmt switch | switch.getExpr() = e)
|
||||
exists(SwitchStmt switch | switch.getExpr() = e and not switch.hasNullCase())
|
||||
or
|
||||
exists(SwitchExpr switch | switch.getExpr() = e)
|
||||
exists(SwitchExpr switch | switch.getExpr() = e and not switch.hasNullCase())
|
||||
or
|
||||
exists(FieldAccess fa, Field f | fa.getQualifier() = e and fa.getField() = f and not f.isStatic())
|
||||
or
|
||||
|
||||
Reference in New Issue
Block a user