Skip to content

Commit aa522b5

Browse files
authored
Merge pull request #4098 from jbj/SimpleRangeAnalysis-mul-constant
C++: Support multiplication by constants in range analysis
2 parents a457d54 + b1c0e6f commit aa522b5

File tree

7 files changed

+262
-61
lines changed

7 files changed

+262
-61
lines changed

change-notes/1.26/analysis-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ The following changes in version 1.26 affect C/C++ analysis in all applications.
2121

2222
* The models library now models many more taint flows through `std::string`.
2323
* The `SimpleRangeAnalysis` library now supports multiplications of the form
24-
`e1 * e2` when `e1` and `e2` are unsigned.
24+
`e1 * e2` and `x *= e2` when `e1` and `e2` are unsigned or constant.

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,17 @@ class BinaryOperation extends Operation, @bin_op_expr {
539539
/** Gets the right operand of this binary operation. */
540540
Expr getRightOperand() { this.hasChild(result, 1) }
541541

542+
/**
543+
* Holds if `e1` and `e2` (in either order) are the two operands of this
544+
* binary operation.
545+
*/
546+
predicate hasOperands(Expr e1, Expr e2) {
547+
exists(int i | i in [0, 1] |
548+
this.hasChild(e1, i) and
549+
this.hasChild(e2, 1 - i)
550+
)
551+
}
552+
542553
override string toString() { result = "... " + this.getOperator() + " ..." }
543554

544555
override predicate mayBeImpure() {

0 commit comments

Comments
 (0)