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