|
15 | 15 |
|
16 | 16 | import cpp |
17 | 17 | import codingstandards.cpp.autosar |
18 | | -import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis |
| 18 | +import codingstandards.cpp.rules.uncheckedrangedomainpoleerrors.UncheckedRangeDomainPoleErrors |
19 | 19 |
|
20 | | -bindingset[name] |
21 | | -Function getMathVariants(string name) { result.hasGlobalOrStdName([name, name + "f", name + "l"]) } |
22 | | - |
23 | | -predicate hasDomainError(FunctionCall fc, string description) { |
24 | | - exists(Function functionWithDomainError | fc.getTarget() = functionWithDomainError | |
25 | | - functionWithDomainError = [getMathVariants(["acos", "asin", "atanh"])] and |
26 | | - not ( |
27 | | - upperBound(fc.getArgument(0)) <= 1.0 and |
28 | | - lowerBound(fc.getArgument(0)) >= -1.0 |
29 | | - ) and |
30 | | - description = |
31 | | - "the argument has a range " + lowerBound(fc.getArgument(0)) + "..." + |
32 | | - upperBound(fc.getArgument(0)) + " which is outside the domain of this function (-1.0...1.0)" |
33 | | - or |
34 | | - functionWithDomainError = getMathVariants(["atan2", "pow"]) and |
35 | | - ( |
36 | | - fc.getArgument(0).getValue().toFloat() = 0 and |
37 | | - fc.getArgument(1).getValue().toFloat() = 0 and |
38 | | - description = "both arguments are equal to zero" |
39 | | - ) |
40 | | - or |
41 | | - functionWithDomainError = getMathVariants("pow") and |
42 | | - ( |
43 | | - upperBound(fc.getArgument(0)) < 0.0 and |
44 | | - upperBound(fc.getArgument(1)) < 0.0 and |
45 | | - description = "both arguments are less than zero" |
46 | | - ) |
47 | | - or |
48 | | - functionWithDomainError = getMathVariants("acosh") and |
49 | | - upperBound(fc.getArgument(0)) < 1.0 and |
50 | | - description = "argument is less than 1" |
51 | | - or |
52 | | - functionWithDomainError = getMathVariants(["ilogb", "logb", "tgamma"]) and |
53 | | - fc.getArgument(0).getValue().toFloat() = 0 and |
54 | | - description = "argument is equal to zero" |
55 | | - or |
56 | | - functionWithDomainError = getMathVariants(["log", "log10", "log2", "sqrt"]) and |
57 | | - upperBound(fc.getArgument(0)) < 0.0 and |
58 | | - description = "argument is negative" |
59 | | - or |
60 | | - functionWithDomainError = getMathVariants("log1p") and |
61 | | - upperBound(fc.getArgument(0)) < -1.0 and |
62 | | - description = "argument is less than 1" |
63 | | - ) |
| 20 | +class UncheckedRangeDomainPoleErrorsQuery extends UncheckedRangeDomainPoleErrorsSharedQuery { |
| 21 | + UncheckedRangeDomainPoleErrorsQuery() { |
| 22 | + this = TypeRangesPackage::uncheckedRangeDomainPoleErrorsQuery() |
| 23 | + } |
64 | 24 | } |
65 | | - |
66 | | -/* |
67 | | - * Domain cases not covered by this query: |
68 | | - * - pow - x is finite and negative and y is finite and not an integer value. |
69 | | - * - tgamma - negative integer can't be covered. |
70 | | - * - lrint/llrint/lround/llround - no domain errors checked |
71 | | - * - fmod - no domain errors checked. |
72 | | - * - remainder - no domain errors checked. |
73 | | - * - remquo - no domain errors checked. |
74 | | - * |
75 | | - * Implementations may also define their own domain errors (as per the C99 standard), which are not |
76 | | - * covered by this query. |
77 | | - */ |
78 | | - |
79 | | -from FunctionCall fc, string description |
80 | | -where |
81 | | - not isExcluded(fc, TypeRangesPackage::uncheckedRangeDomainPoleErrorsQuery()) and |
82 | | - hasDomainError(fc, description) |
83 | | -select fc, "Domain error in call to " + fc.getTarget().getName() + ": " + description + "." |
0 commit comments