Skip to content

Commit 204dbee

Browse files
committed
C++: Move overflow detection to SimpleRangeAnalysis.qll
1 parent 0f4157c commit 204dbee

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/SimpleRangeAnalysis.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import semmle.code.cpp.ir.IR
88
private import experimental.semmle.code.cpp.semantic.SemanticBound
99
private import experimental.semmle.code.cpp.semantic.SemanticExprSpecific
1010
private import RangeAnalysis
11+
private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1112

1213
/**
1314
* Gets the lower bound of the expression.
@@ -90,7 +91,7 @@ predicate defMightOverflow(RangeSsaDefinition def, StackVariable v) {
9091
* does not consider the possibility that the expression might overflow
9192
* due to a conversion.
9293
*/
93-
predicate exprMightOverflowNegatively(Expr expr) { none() }
94+
predicate exprMightOverflowNegatively(Expr expr) { lowerBound(expr) < exprMinVal(expr) }
9495

9596
/**
9697
* Holds if the expression might overflow negatively. Conversions
@@ -108,7 +109,7 @@ predicate convertedExprMightOverflowNegatively(Expr expr) {
108109
* does not consider the possibility that the expression might overflow
109110
* due to a conversion.
110111
*/
111-
predicate exprMightOverflowPositively(Expr expr) { none() }
112+
predicate exprMightOverflowPositively(Expr expr) { upperBound(expr) > exprMaxVal(expr) }
112113

113114
/**
114115
* Holds if the expression might overflow positively. Conversions

0 commit comments

Comments
 (0)