@@ -15,9 +15,9 @@ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
15
15
import semmle.code.cpp.controlflow.Guards
16
16
17
17
/** Holds if function `fn` can return a value equal to value `val` */
18
- predicate mayBeReturnValue ( Function fn , Expr val ) {
18
+ predicate mayBeReturnValue ( Function fn , float val ) {
19
19
exists ( Expr tmpExp , ReturnStmt rs |
20
- tmpExp .getValue ( ) .toFloat ( ) = val . getValue ( ) . toFloat ( ) and
20
+ tmpExp .getValue ( ) .toFloat ( ) = val and
21
21
rs .getEnclosingFunction ( ) = fn and
22
22
(
23
23
globalValueNumber ( rs .getExpr ( ) ) = globalValueNumber ( tmpExp )
@@ -39,7 +39,7 @@ predicate mayBeReturnValue(Function fn, Expr val) {
39
39
40
40
/** Holds if function `fn` can return a value equal zero */
41
41
predicate mayBeReturnZero ( Function fn ) {
42
- exists ( Expr zr | zr . getValue ( ) . toFloat ( ) = 0 and mayBeReturnValue ( fn , zr ) )
42
+ mayBeReturnValue ( fn , 0 )
43
43
or
44
44
fn .hasName ( [
45
45
"iswalpha" , "iswlower" , "iswprint" , "iswspace" , "iswblank" , "iswupper" , "iswcntrl" ,
@@ -101,7 +101,7 @@ predicate compareFunctionWithValue(Expr guardExp, Function compArg, Expr valArg)
101
101
if valArg .getValue ( ) .toFloat ( ) = 0
102
102
then
103
103
exists ( NotExpr ne , IfStmt ifne |
104
- globalValueNumber ( ne .getOperand ( ) ) = globalValueNumber ( compArg .getACallToThisFunction ( ) ) and
104
+ ne .getOperand ( ) = globalValueNumber ( compArg .getACallToThisFunction ( ) ) . getAnExpr ( ) and
105
105
ifne .getCondition ( ) = ne and
106
106
ifne .getThen ( ) .getAChild * ( ) = guardExp
107
107
)
@@ -152,7 +152,7 @@ predicate compareExprWithValue(Expr guardExp, Expr compArg, Expr valArg) {
152
152
if valArg .getValue ( ) .toFloat ( ) = 0
153
153
then
154
154
exists ( NotExpr ne , IfStmt ifne |
155
- globalValueNumber ( ne .getOperand ( ) ) = globalValueNumber ( compArg ) and
155
+ ne .getOperand ( ) = globalValueNumber ( compArg ) . getAnExpr ( ) and
156
156
ifne .getCondition ( ) = ne and
157
157
ifne .getThen ( ) .getAChild * ( ) = guardExp
158
158
)
@@ -222,10 +222,8 @@ where
222
222
changeInt = 0
223
223
or
224
224
// Denominator can be sum or difference.
225
- exists ( Expr changeExpr |
226
- mayBeReturnValue ( fn , changeExpr ) and
227
- changeInt = getValueOperand ( div .getRV ( ) , findVal , changeExpr )
228
- )
225
+ changeInt = getValueOperand ( div .getRV ( ) , findVal , _) and
226
+ mayBeReturnValue ( fn , changeInt )
229
227
) and
230
228
exp = div and
231
229
msg =
@@ -249,19 +247,15 @@ where
249
247
changeInt2 = 0
250
248
or
251
249
// Denominator can be sum or difference.
252
- exists ( Expr changeExpr |
253
- mayBeReturnValue ( fn , changeExpr ) and
254
- changeInt = getValueOperand ( divFc .getArgument ( posArg ) , findVal , changeExpr ) and
255
- changeInt2 = 0
256
- )
250
+ changeInt = getValueOperand ( divFc .getArgument ( posArg ) , findVal , _) and
251
+ mayBeReturnValue ( fn , changeInt ) and
252
+ changeInt2 = 0
257
253
)
258
254
or
259
255
// Look for a situation where the difference or subtraction is considered as an argument, and it can be used in the same way.
260
- exists ( Expr changeExpr |
261
- changeInt = getValueOperand ( div .getRV ( ) , divVal , changeExpr ) and
262
- changeInt2 = changeInt and
263
- mayBeReturnValue ( fn , changeExpr )
264
- ) and
256
+ changeInt = getValueOperand ( div .getRV ( ) , divVal , _) and
257
+ changeInt2 = changeInt and
258
+ mayBeReturnValue ( fn , changeInt ) and
265
259
divFc .getArgument ( posArg ) = findVal
266
260
) and
267
261
checkConditions2 ( div , divVal , changeInt2 ) and
0 commit comments