Skip to content

Commit 7f0ad2d

Browse files
authored
Merge pull request #4646 from hvitved/csharp/cfg/post-order-exprs
C#: Represent all expressions in post-order in the CFG
2 parents 55a3880 + 708fca4 commit 7f0ad2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3642
-3241
lines changed

csharp/ql/src/Bad Practices/Control-Flow/ConstantCondition.ql

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ class ConstantBooleanCondition extends ConstantCondition {
3535

3636
override predicate isWhiteListed() {
3737
// E.g. `x ?? false`
38-
this.(BoolLiteral) = any(NullCoalescingExpr nce).getRightOperand()
38+
this.(BoolLiteral) = any(NullCoalescingExpr nce).getRightOperand() or
39+
// No need to flag logical operations when the operands are constant
40+
isConstantCondition(this.(LogicalNotExpr).getOperand(), _) or
41+
this =
42+
any(LogicalAndExpr lae |
43+
isConstantCondition(lae.getAnOperand(), false)
44+
or
45+
isConstantCondition(lae.getLeftOperand(), true) and
46+
isConstantCondition(lae.getRightOperand(), true)
47+
) or
48+
this =
49+
any(LogicalOrExpr loe |
50+
isConstantCondition(loe.getAnOperand(), true)
51+
or
52+
isConstantCondition(loe.getLeftOperand(), false) and
53+
isConstantCondition(loe.getRightOperand(), false)
54+
)
3955
}
4056
}
4157

@@ -51,7 +67,8 @@ class ConstantIfCondition extends ConstantBooleanCondition {
5167
or
5268
// It is a common pattern to use a local constant/constant field to control
5369
// whether code parts must be executed or not
54-
this instanceof AssignableRead
70+
this instanceof AssignableRead and
71+
not this instanceof ParameterRead
5572
}
5673
}
5774

0 commit comments

Comments
 (0)