Skip to content

Commit 99e92cf

Browse files
formatting fixes
1 parent dee2261 commit 99e92cf

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

c/misra/src/rules/DIR-4-15/PossibleMisuseOfUndetectedInfinity.ql

+8-6
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ where
133133
(
134134
if not sourceExpr.getEnclosingFunction() = usage.asExpr().getEnclosingFunction()
135135
then
136-
extraString = usage.getInfinityDescription() + " computed in function " + sourceExpr.getEnclosingFunction().getName()
137-
and extra = sourceExpr.getEnclosingFunction()
136+
extraString =
137+
usage.getInfinityDescription() + " computed in function " +
138+
sourceExpr.getEnclosingFunction().getName() and
139+
extra = sourceExpr.getEnclosingFunction()
138140
else (
139141
extra = sourceExpr and
140-
if sourceExpr instanceof DivExpr
141-
then extraString = usage.getInfinityDescription() + " from division by zero"
142-
else extraString = usage.getInfinityDescription()
142+
if sourceExpr instanceof DivExpr
143+
then extraString = usage.getInfinityDescription() + " from division by zero"
144+
else extraString = usage.getInfinityDescription()
143145
)
144146
)
145-
select elem, source, sink, usage.getDescription(), extra, extraString
147+
select elem, source, sink, usage.getDescription(), extra, extraString

c/misra/src/rules/DIR-4-15/PossibleMisuseOfUndetectedNaN.ql

+26-29
Original file line numberDiff line numberDiff line change
@@ -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 {
8182
class 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

Comments
 (0)