Skip to content

Commit dcdc439

Browse files
committed
C++: Minor refactor and documentation tweak to simple range analysis
1 parent 0c9ee4d commit dcdc439

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ private float getLowerBoundsImpl(Expr expr) {
769769
exists(float x, float y |
770770
x = getFullyConvertedLowerBounds(maxExpr.getLeftOperand()) and
771771
y = getFullyConvertedLowerBounds(maxExpr.getRightOperand()) and
772-
if x >= y then result = x else result = y
772+
result = x.maximum(y)
773773
)
774774
)
775775
or
@@ -979,7 +979,7 @@ private float getUpperBoundsImpl(Expr expr) {
979979
exists(float x, float y |
980980
x = getFullyConvertedUpperBounds(minExpr.getLeftOperand()) and
981981
y = getFullyConvertedUpperBounds(minExpr.getRightOperand()) and
982-
if x <= y then result = x else result = y
982+
result = x.minimum(y)
983983
)
984984
)
985985
or
@@ -1152,10 +1152,7 @@ private float getUpperBoundsImpl(Expr expr) {
11521152
not expr instanceof SimpleRangeAnalysisExpr
11531153
or
11541154
// A modeled expression for range analysis
1155-
exists(SimpleRangeAnalysisExpr rangeAnalysisExpr |
1156-
rangeAnalysisExpr = expr and
1157-
result = rangeAnalysisExpr.getUpperBounds()
1158-
)
1155+
result = expr.(SimpleRangeAnalysisExpr).getUpperBounds()
11591156
}
11601157

11611158
/**
@@ -1606,7 +1603,7 @@ private module SimpleRangeAnalysisCached {
16061603
* the lower bound of the expression after all the casts have been applied,
16071604
* call `lowerBound` like this:
16081605
*
1609-
* `lowerBound(expr.getFullyConverted())`
1606+
* lowerBound(expr.getFullyConverted())
16101607
*/
16111608
cached
16121609
float lowerBound(Expr expr) {
@@ -1625,7 +1622,7 @@ private module SimpleRangeAnalysisCached {
16251622
* the upper bound of the expression after all the casts have been applied,
16261623
* call `upperBound` like this:
16271624
*
1628-
* `upperBound(expr.getFullyConverted())`
1625+
* upperBound(expr.getFullyConverted())
16291626
*/
16301627
cached
16311628
float upperBound(Expr expr) {

0 commit comments

Comments
 (0)