mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
C#: Remove false positives in cs/constant-condition
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
| **Query** | **Expected impact** | **Change** |
|
||||
|------------------------------|------------------------|-----------------------------------|
|
||||
| Constant condition (`cs/constant-condition`) | Fewer false positive results | Results have been removed for default cases (`_`) in switch expressions. |
|
||||
| Dispose may not be called if an exception is thrown during execution (`cs/dispose-not-called-on-throw`) | Fewer false positive results | Results have been removed where an object is disposed both by a `using` statement and a `Dispose` call. |
|
||||
|
||||
## Changes to code extraction
|
||||
|
||||
@@ -101,6 +101,13 @@ class ConstantMatchingCondition extends ConstantCondition {
|
||||
)
|
||||
}
|
||||
|
||||
override predicate isWhiteListed() {
|
||||
exists(SwitchExpr se |
|
||||
se.getACase().getPattern() = this.(DiscardExpr) and
|
||||
strictcount(se.getACase()) > 1
|
||||
)
|
||||
}
|
||||
|
||||
override string getMessage() {
|
||||
if b = true then result = "Pattern always matches." else result = "Pattern never matches."
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
| ConstantCondition.cs:66:18:66:18 | 3 | Pattern always matches. |
|
||||
| ConstantCondition.cs:77:18:77:20 | access to type Int32 | Pattern never matches. |
|
||||
| ConstantCondition.cs:97:13:97:13 | _ | Pattern always matches. |
|
||||
| ConstantCondition.cs:106:13:106:13 | _ | Pattern always matches. |
|
||||
| ConstantConditionBad.cs:5:16:5:20 | ... > ... | Condition always evaluates to 'false'. |
|
||||
| ConstantConditionalExpressionCondition.cs:11:22:11:34 | ... == ... | Condition always evaluates to 'true'. |
|
||||
| ConstantConditionalExpressionCondition.cs:12:21:12:25 | false | Condition always evaluates to 'false'. |
|
||||
|
||||
Reference in New Issue
Block a user