Skip to content

Commit 25c6e77

Browse files
committed
FloatingTypes: Add query for FLP32-C
FLP32-C is a straight import of the AUTOSAR rule A0-4-4-.
1 parent ec0e4bc commit 25c6e77

File tree

6 files changed

+453
-0
lines changed

6 files changed

+453
-0
lines changed

c/cert/src/rules/FLP32-C/UncheckedRangeDomainPoleErrors.md

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/cert/unchecked-range-domain-pole-errors
3+
* @name FLP32-C: Prevent or detect domain and range errors in math functions
4+
* @description Range, domain or pole errors in math functions may return unexpected values, trigger
5+
* floating-point exceptions or set unexpected error modes.
6+
* @kind problem
7+
* @precision high
8+
* @problem.severity error
9+
* @tags external/cert/id/flp32-c
10+
* correctness
11+
* external/cert/obligation/rule
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.cert
16+
import codingstandards.cpp.rules.uncheckedrangedomainpoleerrors.UncheckedRangeDomainPoleErrors
17+
18+
class UncheckedRangeDomainPoleErrorsQuery extends UncheckedRangeDomainPoleErrorsSharedQuery {
19+
UncheckedRangeDomainPoleErrorsQuery() {
20+
this = FloatingTypesPackage::uncheckedRangeDomainPoleErrorsQuery()
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/uncheckedrangedomainpoleerrors/UncheckedRangeDomainPoleErrors.ql
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
| test.c:4:3:4:6 | call to acos | Domain error in call to acos: the argument has a range -1.1...-1.1 which is outside the domain of this function (-1.0...1.0). |
2+
| test.c:8:3:8:6 | call to acos | Domain error in call to acos: the argument has a range 1.1...1.1 which is outside the domain of this function (-1.0...1.0). |
3+
| test.c:9:3:9:6 | call to asin | Domain error in call to asin: the argument has a range -1.1...-1.1 which is outside the domain of this function (-1.0...1.0). |
4+
| test.c:13:3:13:6 | call to asin | Domain error in call to asin: the argument has a range 1.1...1.1 which is outside the domain of this function (-1.0...1.0). |
5+
| test.c:14:3:14:7 | call to atanh | Domain error in call to atanh: the argument has a range -1.1...-1.1 which is outside the domain of this function (-1.0...1.0). |
6+
| test.c:18:3:18:7 | call to atanh | Domain error in call to atanh: the argument has a range 1.1...1.1 which is outside the domain of this function (-1.0...1.0). |
7+
| test.c:19:3:19:7 | call to atan2 | Domain error in call to atan2: both arguments are equal to zero. |
8+
| test.c:23:3:23:5 | call to pow | Domain error in call to pow: both arguments are equal to zero. |
9+
| test.c:27:3:27:5 | call to pow | Domain error in call to pow: both arguments are less than zero. |
10+
| test.c:33:3:33:7 | call to acosh | Domain error in call to acosh: argument is less than 1. |
11+
| test.c:34:3:34:7 | call to ilogb | Domain error in call to ilogb: argument is equal to zero. |
12+
| test.c:37:3:37:5 | call to log | Domain error in call to log: argument is negative. |
13+
| test.c:40:3:40:7 | call to log10 | Domain error in call to log10: argument is negative. |
14+
| test.c:43:3:43:6 | call to log2 | Domain error in call to log2: argument is negative. |
15+
| test.c:46:3:46:6 | call to sqrt | Domain error in call to sqrt: argument is negative. |
16+
| test.c:49:3:49:7 | call to log1p | Domain error in call to log1p: argument is less than 1. |
17+
| test.c:52:3:52:6 | call to logb | Domain error in call to logb: argument is equal to zero. |
18+
| test.c:55:3:55:8 | call to tgamma | Domain error in call to tgamma: argument is equal to zero. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.uncheckedrangedomainpoleerrors.UncheckedRangeDomainPoleErrors
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <math.h>
2+
3+
void test() {
4+
acos(-1.1f); // NON_COMPLIANT
5+
acos(-1.0f); // COMPLIANT
6+
acos(0.0f); // COMPLIANT
7+
acos(1.0f); // COMPLIANT
8+
acos(1.1f); // NON_COMPLIANT
9+
asin(-1.1f); // NON_COMPLIANT
10+
asin(-1.0f); // COMPLIANT
11+
asin(0.0f); // COMPLIANT
12+
asin(1.0f); // COMPLIANT
13+
asin(1.1f); // NON_COMPLIANT
14+
atanh(-1.1f); // NON_COMPLIANT
15+
atanh(-1.0f); // COMPLIANT
16+
atanh(0.0f); // COMPLIANT
17+
atanh(1.0f); // COMPLIANT
18+
atanh(1.1f); // NON_COMPLIANT
19+
atan2(0.0f, 0.0f); // NON_COMPLIANT
20+
atan2(1.0f, 0.0f); // COMPLIANT
21+
atan2(0.0f, 1.0f); // COMPLIANT
22+
atan2(1.0f, 1.0f); // COMPLIANT
23+
pow(0.0f, 0.0f); // NON_COMPLIANT
24+
pow(1.0f, 0.0f); // COMPLIANT
25+
pow(0.0f, 1.0f); // COMPLIANT
26+
pow(1.0f, 1.0f); // COMPLIANT
27+
pow(-1.0f, -1.0f); // NON_COMPLIANT
28+
pow(-1.0f, 0.0f); // COMPLIANT
29+
pow(0.0f, -1.0f); // COMPLIANT
30+
pow(1.0f, -1.0f); // COMPLIANT
31+
pow(-1.0f, 1.0f); // COMPLIANT
32+
acosh(1.0f); // COMPLIANT
33+
acosh(0.9f); // NON_COMPLIANT
34+
ilogb(0.0f); // NON_COMPLIANT
35+
ilogb(1.0f); // COMPLIANT
36+
ilogb(-1.0f); // COMPLIANT
37+
log(-1.0f); // NON_COMPLIANT
38+
log(0.0f); // COMPLIANT
39+
log(1.0f); // COMPLIANT
40+
log10(-1.0f); // NON_COMPLIANT
41+
log10(0.0f); // COMPLIANT
42+
log10(1.0f); // COMPLIANT
43+
log2(-1.0f); // NON_COMPLIANT
44+
log2(0.0f); // COMPLIANT
45+
log2(1.0f); // COMPLIANT
46+
sqrt(-1.0f); // NON_COMPLIANT
47+
sqrt(0.0f); // COMPLIANT
48+
sqrt(1.0f); // COMPLIANT
49+
log1p(-2.0f); // NON_COMPLIANT
50+
log1p(-1.0f); // COMPLIANT
51+
log1p(0.0f); // COMPLIANT
52+
logb(0.0f); // NON_COMPLIANT
53+
logb(1.0f); // COMPLIANT
54+
logb(-1.0f); // COMPLIANT
55+
tgamma(0.0f); // NON_COMPLIANT
56+
tgamma(1.0f); // COMPLIANT
57+
tgamma(-1.1f); // COMPLIANT
58+
}

0 commit comments

Comments
 (0)