@@ -35,7 +35,8 @@ predicate hasDomainError(FunctionCall fc, string description) {
3535 ) and
3636 description =
3737 "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)"
3940 or
4041 functionWithDomainError = getMathVariants ( [ "atan2" , "pow" ] ) and
4142 (
@@ -81,9 +82,7 @@ abstract class PotentiallyNaNExpr extends Expr {
8182class DomainErrorFunctionCall extends FunctionCall , PotentiallyNaNExpr {
8283 string reason ;
8384
84- DomainErrorFunctionCall ( ) {
85- hasDomainError ( this , reason )
86- }
85+ DomainErrorFunctionCall ( ) { hasDomainError ( this , reason ) }
8786
8887 override string getReason ( ) { result = reason }
8988}
@@ -203,25 +202,22 @@ class InvalidNaNUsage extends DataFlow::Node {
203202 string nanDescription ;
204203
205204 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+ )
225221 }
226222
227223 string getDescription ( ) { result = description }
@@ -244,17 +240,18 @@ where
244240 elem = MacroUnwrapper< Expr > :: unwrapElement ( sink .getNode ( ) .asExpr ( ) ) and
245241 usage = sink .getNode ( ) and
246242 sourceExpr = source .getNode ( ) .asExpr ( ) and
247- sourceString =
248- " (" + source .getNode ( ) .asExpr ( ) .( PotentiallyNaNExpr ) .getReason ( ) + ")" and
243+ sourceString = " (" + source .getNode ( ) .asExpr ( ) .( PotentiallyNaNExpr ) .getReason ( ) + ")" and
249244 InvalidNaNFlow:: flow ( source .getNode ( ) , usage ) and
250245 (
251246 if not sourceExpr .getEnclosingFunction ( ) = usage .asExpr ( ) .getEnclosingFunction ( )
252247 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 ( )
255252 else (
256253 extra = sourceExpr and
257- extraString = usage .getNaNDescription ( ) + sourceString
254+ extraString = usage .getNaNDescription ( ) + sourceString
258255 )
259256 )
260- select elem , source , sink , usage .getDescription ( ) , extra , extraString
257+ select elem , source , sink , usage .getDescription ( ) , extra , extraString
0 commit comments