Skip to content

Commit 9e2812c

Browse files
committed
Sync ConditionalExpr changes with csharp
1 parent 7a6db06 commit 9e2812c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/ModulusAnalysis.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ predicate exprModulus(Expr e, Bound b, int val, int mod) {
268268
private predicate condExprBranchModulus(
269269
ConditionalExpr cond, boolean branch, Bound b, int val, int mod
270270
) {
271-
exprModulus(cond.getTrueExpr(), b, val, mod) and branch = true
272-
or
273-
exprModulus(cond.getFalseExpr(), b, val, mod) and branch = false
271+
exprModulus(cond.getBranchExpr(branch), b, val, mod)
274272
}
275273

276274
private predicate addModulus(Expr add, boolean isLeft, Bound b, int val, int mod) {

csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/RangeUtils.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,5 +415,15 @@ module ExprNode {
415415

416416
/** Gets the "else" expression of this conditional expression. */
417417
ExprNode getFalseExpr() { hasChild(e, e.getElse(), this, result) }
418+
419+
/**
420+
* If `branch` is `true` gets the "then" expression, if `false` gets the
421+
* "else" expression of this conditional expression.
422+
*/
423+
ExprNode getBranchExpr(boolean branch) {
424+
branch = true and result = getTrueExpr()
425+
or
426+
branch = false and result = getFalseExpr()
427+
}
418428
}
419429
}

0 commit comments

Comments
 (0)