6
6
import cpp
7
7
import semmle.code.cpp.controlflow.Dominance
8
8
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
9
+ import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
9
10
10
11
/**
11
12
* Holds if the value of `use` is guarded using `abs`.
@@ -98,7 +99,12 @@ VariableAccess varUse(LocalScopeVariable v) { result = v.getAnAccess() }
98
99
* Holds if `e` potentially overflows and `use` is an operand of `e` that is not guarded.
99
100
*/
100
101
predicate missingGuardAgainstOverflow ( Operation e , VariableAccess use ) {
101
- convertedExprMightOverflowPositively ( e ) and
102
+ (
103
+ convertedExprMightOverflowPositively ( e )
104
+ or
105
+ // Ensure that the predicate holds when range analysis cannot determine an upper bound
106
+ upperBound ( e .getFullyConverted ( ) ) = exprMaxVal ( e .getFullyConverted ( ) )
107
+ ) and
102
108
use = e .getAnOperand ( ) and
103
109
exists ( LocalScopeVariable v | use .getTarget ( ) = v |
104
110
// overflow possible if large
@@ -120,7 +126,12 @@ predicate missingGuardAgainstOverflow(Operation e, VariableAccess use) {
120
126
* Holds if `e` potentially underflows and `use` is an operand of `e` that is not guarded.
121
127
*/
122
128
predicate missingGuardAgainstUnderflow ( Operation e , VariableAccess use ) {
123
- convertedExprMightOverflowNegatively ( e ) and
129
+ (
130
+ convertedExprMightOverflowNegatively ( e )
131
+ or
132
+ // Ensure that the predicate holds when range analysis cannot determine a lower bound
133
+ lowerBound ( e .getFullyConverted ( ) ) = exprMinVal ( e .getFullyConverted ( ) )
134
+ ) and
124
135
use = e .getAnOperand ( ) and
125
136
exists ( LocalScopeVariable v | use .getTarget ( ) = v |
126
137
// underflow possible if use is left operand and small
0 commit comments