@@ -35,7 +35,8 @@ predicate hasDomainError(FunctionCall fc, string description) {
35
35
) and
36
36
description =
37
37
"the argument has a range " + RestrictedRangeAnalysis:: lowerBound ( fc .getArgument ( 0 ) ) + "..." +
38
- RestrictedRangeAnalysis:: upperBound ( fc .getArgument ( 0 ) ) + " which is outside the domain of this function (-1.0...1.0)"
38
+ RestrictedRangeAnalysis:: upperBound ( fc .getArgument ( 0 ) ) +
39
+ " which is outside the domain of this function (-1.0...1.0)"
39
40
or
40
41
functionWithDomainError = getMathVariants ( [ "atan2" , "pow" ] ) and
41
42
(
@@ -81,9 +82,7 @@ abstract class PotentiallyNaNExpr extends Expr {
81
82
class DomainErrorFunctionCall extends FunctionCall , PotentiallyNaNExpr {
82
83
string reason ;
83
84
84
- DomainErrorFunctionCall ( ) {
85
- hasDomainError ( this , reason )
86
- }
85
+ DomainErrorFunctionCall ( ) { hasDomainError ( this , reason ) }
87
86
88
87
override string getReason ( ) { result = reason }
89
88
}
@@ -203,25 +202,22 @@ class InvalidNaNUsage extends DataFlow::Node {
203
202
string nanDescription ;
204
203
205
204
InvalidNaNUsage ( ) {
206
- // Case 1: NaNs shall not be compared, except to themselves
207
- exists ( ComparisonOperation cmp |
208
- this .asExpr ( ) = cmp .getAnOperand ( ) and
209
- not hashCons ( cmp .getLeftOperand ( ) ) = hashCons ( cmp .getRightOperand ( ) ) and
210
- description = "Comparison involving a $@, which always evaluates to false." and
211
- nanDescription = "possibly NaN float value"
212
- )
213
- or
214
- // Case 2: NaNs and infinities shall not be cast to integers
215
- exists ( Conversion c |
216
- this .asExpr ( ) = c .getUnconverted ( ) and
217
- c .getExpr ( ) .getType ( ) instanceof FloatingPointType and
218
- c .getType ( ) instanceof IntegralType and
219
- description = "$@ casted to integer." and
220
- nanDescription = "Possibly NaN float value"
221
- )
222
- //or
223
- //// Case 4: Functions shall not return NaNs or infinities
224
- //exists(ReturnStmt ret | node.asExpr() = ret.getExpr())
205
+ // Case 1: NaNs shall not be compared, except to themselves
206
+ exists ( ComparisonOperation cmp |
207
+ this .asExpr ( ) = cmp .getAnOperand ( ) and
208
+ not hashCons ( cmp .getLeftOperand ( ) ) = hashCons ( cmp .getRightOperand ( ) ) and
209
+ description = "Comparison involving a $@, which always evaluates to false." and
210
+ nanDescription = "possibly NaN float value"
211
+ )
212
+ or
213
+ // Case 2: NaNs and infinities shall not be cast to integers
214
+ exists ( Conversion c |
215
+ this .asExpr ( ) = c .getUnconverted ( ) and
216
+ c .getExpr ( ) .getType ( ) instanceof FloatingPointType and
217
+ c .getType ( ) instanceof IntegralType and
218
+ description = "$@ casted to integer." and
219
+ nanDescription = "Possibly NaN float value"
220
+ )
225
221
}
226
222
227
223
string getDescription ( ) { result = description }
@@ -244,17 +240,18 @@ where
244
240
elem = MacroUnwrapper< Expr > :: unwrapElement ( sink .getNode ( ) .asExpr ( ) ) and
245
241
usage = sink .getNode ( ) and
246
242
sourceExpr = source .getNode ( ) .asExpr ( ) and
247
- sourceString =
248
- " (" + source .getNode ( ) .asExpr ( ) .( PotentiallyNaNExpr ) .getReason ( ) + ")" and
243
+ sourceString = " (" + source .getNode ( ) .asExpr ( ) .( PotentiallyNaNExpr ) .getReason ( ) + ")" and
249
244
InvalidNaNFlow:: flow ( source .getNode ( ) , usage ) and
250
245
(
251
246
if not sourceExpr .getEnclosingFunction ( ) = usage .asExpr ( ) .getEnclosingFunction ( )
252
247
then
253
- extraString = usage .getNaNDescription ( ) + sourceString + " computed in function " + sourceExpr .getEnclosingFunction ( ) .getName ( )
254
- and extra = sourceExpr .getEnclosingFunction ( )
248
+ extraString =
249
+ usage .getNaNDescription ( ) + sourceString + " computed in function " +
250
+ sourceExpr .getEnclosingFunction ( ) .getName ( ) and
251
+ extra = sourceExpr .getEnclosingFunction ( )
255
252
else (
256
253
extra = sourceExpr and
257
- extraString = usage .getNaNDescription ( ) + sourceString
254
+ extraString = usage .getNaNDescription ( ) + sourceString
258
255
)
259
256
)
260
- select elem , source , sink , usage .getDescription ( ) , extra , extraString
257
+ select elem , source , sink , usage .getDescription ( ) , extra , extraString
0 commit comments