mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Replace getDefaultOrNullDefaultCase with getDefaultCase
This commit is contained in:
@@ -14,5 +14,5 @@ where
|
||||
switch.getExpr().getType() = enum and
|
||||
missing.getDeclaringType() = enum and
|
||||
not switch.getAConstCase().getValue() = missing.getAnAccess() and
|
||||
not exists(switch.getDefaultOrNullDefaultCase())
|
||||
not exists(switch.getDefaultCase())
|
||||
select switch
|
||||
|
||||
@@ -923,7 +923,7 @@ private module ControlFlowGraphImpl {
|
||||
completion = NormalCompletion()
|
||||
or
|
||||
// if no default case exists, then normal completion of the expression may terminate the switch
|
||||
not exists(switch.getDefaultOrNullDefaultCase()) and
|
||||
not exists(switch.getDefaultCase()) and
|
||||
last(switch.getExpr(), last, completion) and
|
||||
completion = NormalCompletion()
|
||||
)
|
||||
|
||||
@@ -1530,11 +1530,12 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
|
||||
/** Gets a (non-default) pattern `case` of this `switch` expression. */
|
||||
PatternCase getAPatternCase() { result = this.getACase() }
|
||||
|
||||
/** Gets the `default` case of this switch expression, if any. */
|
||||
DefaultCase getDefaultCase() { result = this.getACase() }
|
||||
|
||||
/** Gets the `default` or `case null, default` case of this switch statement, if any. */
|
||||
SwitchCase getDefaultOrNullDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
|
||||
/**
|
||||
* Gets the `default` case of this switch statement, if any.
|
||||
*
|
||||
* Note this may be `default` or `case null, default`.
|
||||
*/
|
||||
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
|
||||
|
||||
/** Gets the expression of this `switch` expression. */
|
||||
Expr getExpr() { result.getParent() = this }
|
||||
|
||||
@@ -403,11 +403,12 @@ class SwitchStmt extends Stmt, @switchstmt {
|
||||
/** Gets a (non-default) pattern `case` of this `switch` statement. */
|
||||
PatternCase getAPatternCase() { result = this.getACase() }
|
||||
|
||||
/** Gets the `default` case of this switch statement, if any. */
|
||||
DefaultCase getDefaultCase() { result = this.getACase() }
|
||||
|
||||
/** Gets the `default` or `case null, default` case of this switch statement, if any. */
|
||||
SwitchCase getDefaultOrNullDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
|
||||
/**
|
||||
* Gets the `default` case of this switch statement, if any.
|
||||
*
|
||||
* Note this may be `default` or `case null, default`.
|
||||
*/
|
||||
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
|
||||
|
||||
/** Gets the expression of this `switch` statement. */
|
||||
Expr getExpr() { result.getParent() = this }
|
||||
|
||||
@@ -174,7 +174,7 @@ class ConstSwitchStmt extends SwitchStmt {
|
||||
exists(this.getExpr().(ConstantExpr).getIntValue()) and
|
||||
if exists(this.getMatchingConstCase())
|
||||
then result = this.getMatchingConstCase()
|
||||
else result = this.getDefaultOrNullDefaultCase()
|
||||
else result = this.getDefaultCase()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,5 +15,5 @@ import java
|
||||
from SwitchStmt switch
|
||||
where
|
||||
not switch.getExpr().getType() instanceof EnumType and
|
||||
not exists(switch.getDefaultOrNullDefaultCase())
|
||||
not exists(switch.getDefaultCase())
|
||||
select switch, "Switch statement does not have a default case."
|
||||
|
||||
@@ -17,6 +17,6 @@ from SwitchStmt switch, EnumType enum, EnumConstant missing
|
||||
where
|
||||
switch.getExpr().getType() = enum and
|
||||
missing.getDeclaringType() = enum and
|
||||
not exists(switch.getDefaultOrNullDefaultCase()) and
|
||||
not exists(switch.getDefaultCase()) and
|
||||
not switch.getAConstCase().getValue() = missing.getAnAccess()
|
||||
select switch, "Switch statement does not have a case for $@.", missing, missing.getName()
|
||||
|
||||
Reference in New Issue
Block a user