Skip to content

Commit 5fa421b

Browse files
Format
1 parent 6504537 commit 5fa421b

File tree

10 files changed

+289
-263
lines changed

10 files changed

+289
-263
lines changed

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void addNaNThenCastToInt(float p) { castToInt(p + 0.0 / 0.0); }
192192
void f2() {
193193
castToInt(1.0 /
194194
0.0); // NON_COMPLIANT: Infinity flows to denominator in division
195-
castToInt(0.0 / 0.0); // COMPLIANT
195+
castToInt(0.0 / 0.0); // COMPLIANT
196196
checkBeforeCastToInt(1.0 / 0.0); // COMPLIANT
197197
checkBeforeCastToInt(0.0 / 0.0); // COMPLIANT
198198
addOneThenCastToInt(1.0 / 0.0); // NON_COMPLIANT[False negative]

c/common/test/rules/misuseofnanfloatingpointvalue/MisuseOfNaNFloatingPointValue.expected

+47-47
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ problems
2424
| test.c:155:25:155:27 | l13 | test.c:122:15:122:21 | ... / ... | test.c:155:20:155:27 | l13 | Possible NaN value $@ flows to a cast to integer. | test.c:122:15:122:21 | ... / ... | from division of zero by zero | test.c:6:6:6:7 | f1 | f1 |
2525
| test.c:157:28:157:30 | l13 | test.c:122:15:122:21 | ... / ... | test.c:157:23:157:30 | l13 | Possible NaN value $@ flows to a cast to integer. | test.c:122:15:122:21 | ... / ... | from division of zero by zero | test.c:6:6:6:7 | f1 | f1 |
2626
| test.c:158:21:158:23 | l13 | test.c:122:15:122:21 | ... / ... | test.c:158:16:158:23 | l13 | Possible NaN value $@ flows to a cast to integer. | test.c:122:15:122:21 | ... / ... | from division of zero by zero | test.c:6:6:6:7 | f1 | f1 |
27-
| test.c:166:8:166:10 | call to pow | test.c:166:3:166:18 | call to pow | test.c:166:3:166:18 | call to pow | Possible NaN value $@ flows to a cast to integer. | test.c:166:8:166:10 | call to pow | both arguments are equal to zero | test.c:6:6:6:7 | f1 | f1 |
28-
| test.c:171:8:171:11 | call to acos | test.c:171:3:171:15 | call to acos | test.c:171:3:171:15 | call to acos | Possible NaN value $@ flows to a cast to integer. | test.c:171:8:171:11 | call to acos | the argument has a range -1000000000000000...1000000000000000 which is outside the domain of this function (-1.0...1.0) | test.c:6:6:6:7 | f1 | f1 |
29-
| test.c:175:32:175:32 | p | test.c:190:51:190:59 | ... / ... | test.c:175:27:175:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:190:51:190:59 | ... / ... | from division of zero by zero | test.c:190:6:190:24 | addNaNThenCastToInt | addNaNThenCastToInt |
30-
| test.c:175:32:175:32 | p | test.c:195:13:195:21 | ... / ... | test.c:175:27:175:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:195:13:195:21 | ... / ... | from division of zero by zero | test.c:192:6:192:7 | f2 | f2 |
31-
| test.c:175:32:175:32 | p | test.c:199:23:199:31 | ... / ... | test.c:175:27:175:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:199:23:199:31 | ... / ... | from division of zero by zero | test.c:192:6:192:7 | f2 | f2 |
32-
| test.c:175:32:175:32 | p | test.c:205:19:205:27 | ... / ... | test.c:175:27:175:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:205:19:205:27 | ... / ... | from division of zero by zero | test.c:192:6:192:7 | f2 | f2 |
33-
| test.c:185:18:185:18 | p | test.c:201:25:201:33 | ... / ... | test.c:185:13:185:18 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:201:25:201:33 | ... / ... | from division of zero by zero | test.c:192:6:192:7 | f2 | f2 |
27+
| test.c:165:8:165:10 | call to pow | test.c:165:3:165:18 | call to pow | test.c:165:3:165:18 | call to pow | Possible NaN value $@ flows to a cast to integer. | test.c:165:8:165:10 | call to pow | both arguments are equal to zero | test.c:6:6:6:7 | f1 | f1 |
28+
| test.c:170:8:170:11 | call to acos | test.c:170:3:170:15 | call to acos | test.c:170:3:170:15 | call to acos | Possible NaN value $@ flows to a cast to integer. | test.c:170:8:170:11 | call to acos | the argument has a range -1000000000000000...1000000000000000 which is outside the domain of this function (-1.0...1.0) | test.c:6:6:6:7 | f1 | f1 |
29+
| test.c:174:32:174:32 | p | test.c:189:51:189:59 | ... / ... | test.c:174:27:174:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:189:51:189:59 | ... / ... | from division of zero by zero | test.c:189:6:189:24 | addNaNThenCastToInt | addNaNThenCastToInt |
30+
| test.c:174:32:174:32 | p | test.c:193:13:193:21 | ... / ... | test.c:174:27:174:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:193:13:193:21 | ... / ... | from division of zero by zero | test.c:191:6:191:7 | f2 | f2 |
31+
| test.c:174:32:174:32 | p | test.c:197:23:197:31 | ... / ... | test.c:174:27:174:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:197:23:197:31 | ... / ... | from division of zero by zero | test.c:191:6:191:7 | f2 | f2 |
32+
| test.c:174:32:174:32 | p | test.c:203:19:203:27 | ... / ... | test.c:174:27:174:32 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:203:19:203:27 | ... / ... | from division of zero by zero | test.c:191:6:191:7 | f2 | f2 |
33+
| test.c:184:18:184:18 | p | test.c:199:25:199:33 | ... / ... | test.c:184:13:184:18 | p | Possible NaN value $@ computed in function $@ flows to a cast to integer. | test.c:199:25:199:33 | ... / ... | from division of zero by zero | test.c:191:6:191:7 | f2 | f2 |
3434
edges
3535
| test.c:27:14:27:20 | ... / ... | test.c:27:14:27:20 | ... / ... | provenance | |
3636
| test.c:27:14:27:20 | ... / ... | test.c:36:3:36:9 | l5 | provenance | |
@@ -58,24 +58,24 @@ edges
5858
| test.c:122:15:122:21 | ... / ... | test.c:155:20:155:27 | l13 | provenance | |
5959
| test.c:122:15:122:21 | ... / ... | test.c:157:23:157:30 | l13 | provenance | |
6060
| test.c:122:15:122:21 | ... / ... | test.c:158:16:158:23 | l13 | provenance | |
61-
| test.c:175:22:175:22 | p | test.c:175:27:175:32 | p | provenance | |
62-
| test.c:183:34:183:34 | p | test.c:185:13:185:18 | p | provenance | |
63-
| test.c:188:32:188:32 | p | test.c:188:47:188:51 | ... + ... | provenance | Config |
64-
| test.c:188:47:188:51 | ... + ... | test.c:175:22:175:22 | p | provenance | |
65-
| test.c:190:32:190:32 | p | test.c:190:47:190:59 | ... + ... | provenance | Config |
66-
| test.c:190:47:190:59 | ... + ... | test.c:175:22:175:22 | p | provenance | |
67-
| test.c:190:47:190:59 | ... + ... | test.c:175:22:175:22 | p | provenance | |
68-
| test.c:190:51:190:59 | ... / ... | test.c:190:47:190:59 | ... + ... | provenance | Config |
69-
| test.c:195:13:195:21 | ... / ... | test.c:175:22:175:22 | p | provenance | |
70-
| test.c:199:23:199:31 | ... / ... | test.c:188:32:188:32 | p | provenance | |
71-
| test.c:201:25:201:33 | ... / ... | test.c:183:34:183:34 | p | provenance | |
72-
| test.c:205:19:205:27 | ... / ... | test.c:205:19:205:27 | ... / ... | provenance | |
73-
| test.c:205:19:205:27 | ... / ... | test.c:207:21:207:31 | ... + ... | provenance | Config |
74-
| test.c:207:21:207:31 | ... + ... | test.c:207:21:207:31 | ... + ... | provenance | |
75-
| test.c:207:21:207:31 | ... + ... | test.c:209:13:209:21 | middleNaN | provenance | |
76-
| test.c:207:21:207:31 | ... + ... | test.c:211:23:211:31 | middleNaN | provenance | |
77-
| test.c:209:13:209:21 | middleNaN | test.c:175:22:175:22 | p | provenance | |
78-
| test.c:211:23:211:31 | middleNaN | test.c:190:32:190:32 | p | provenance | |
61+
| test.c:174:22:174:22 | p | test.c:174:27:174:32 | p | provenance | |
62+
| test.c:182:34:182:34 | p | test.c:184:13:184:18 | p | provenance | |
63+
| test.c:187:32:187:32 | p | test.c:187:47:187:51 | ... + ... | provenance | Config |
64+
| test.c:187:47:187:51 | ... + ... | test.c:174:22:174:22 | p | provenance | |
65+
| test.c:189:32:189:32 | p | test.c:189:47:189:59 | ... + ... | provenance | Config |
66+
| test.c:189:47:189:59 | ... + ... | test.c:174:22:174:22 | p | provenance | |
67+
| test.c:189:47:189:59 | ... + ... | test.c:174:22:174:22 | p | provenance | |
68+
| test.c:189:51:189:59 | ... / ... | test.c:189:47:189:59 | ... + ... | provenance | Config |
69+
| test.c:193:13:193:21 | ... / ... | test.c:174:22:174:22 | p | provenance | |
70+
| test.c:197:23:197:31 | ... / ... | test.c:187:32:187:32 | p | provenance | |
71+
| test.c:199:25:199:33 | ... / ... | test.c:182:34:182:34 | p | provenance | |
72+
| test.c:203:19:203:27 | ... / ... | test.c:203:19:203:27 | ... / ... | provenance | |
73+
| test.c:203:19:203:27 | ... / ... | test.c:205:21:205:31 | ... + ... | provenance | Config |
74+
| test.c:205:21:205:31 | ... + ... | test.c:205:21:205:31 | ... + ... | provenance | |
75+
| test.c:205:21:205:31 | ... + ... | test.c:207:13:207:21 | middleNaN | provenance | |
76+
| test.c:205:21:205:31 | ... + ... | test.c:209:23:209:31 | middleNaN | provenance | |
77+
| test.c:207:13:207:21 | middleNaN | test.c:174:22:174:22 | p | provenance | |
78+
| test.c:209:23:209:31 | middleNaN | test.c:189:32:189:32 | p | provenance | |
7979
nodes
8080
| test.c:27:14:27:20 | ... / ... | semmle.label | ... / ... |
8181
| test.c:27:14:27:20 | ... / ... | semmle.label | ... / ... |
@@ -112,25 +112,25 @@ nodes
112112
| test.c:155:20:155:27 | l13 | semmle.label | l13 |
113113
| test.c:157:23:157:30 | l13 | semmle.label | l13 |
114114
| test.c:158:16:158:23 | l13 | semmle.label | l13 |
115-
| test.c:166:3:166:18 | call to pow | semmle.label | call to pow |
116-
| test.c:171:3:171:15 | call to acos | semmle.label | call to acos |
117-
| test.c:175:22:175:22 | p | semmle.label | p |
118-
| test.c:175:27:175:32 | p | semmle.label | p |
119-
| test.c:183:34:183:34 | p | semmle.label | p |
120-
| test.c:185:13:185:18 | p | semmle.label | p |
121-
| test.c:188:32:188:32 | p | semmle.label | p |
122-
| test.c:188:47:188:51 | ... + ... | semmle.label | ... + ... |
123-
| test.c:190:32:190:32 | p | semmle.label | p |
124-
| test.c:190:47:190:59 | ... + ... | semmle.label | ... + ... |
125-
| test.c:190:47:190:59 | ... + ... | semmle.label | ... + ... |
126-
| test.c:190:51:190:59 | ... / ... | semmle.label | ... / ... |
127-
| test.c:195:13:195:21 | ... / ... | semmle.label | ... / ... |
128-
| test.c:199:23:199:31 | ... / ... | semmle.label | ... / ... |
129-
| test.c:201:25:201:33 | ... / ... | semmle.label | ... / ... |
130-
| test.c:205:19:205:27 | ... / ... | semmle.label | ... / ... |
131-
| test.c:205:19:205:27 | ... / ... | semmle.label | ... / ... |
132-
| test.c:207:21:207:31 | ... + ... | semmle.label | ... + ... |
133-
| test.c:207:21:207:31 | ... + ... | semmle.label | ... + ... |
134-
| test.c:209:13:209:21 | middleNaN | semmle.label | middleNaN |
135-
| test.c:211:23:211:31 | middleNaN | semmle.label | middleNaN |
136-
subpaths
115+
| test.c:165:3:165:18 | call to pow | semmle.label | call to pow |
116+
| test.c:170:3:170:15 | call to acos | semmle.label | call to acos |
117+
| test.c:174:22:174:22 | p | semmle.label | p |
118+
| test.c:174:27:174:32 | p | semmle.label | p |
119+
| test.c:182:34:182:34 | p | semmle.label | p |
120+
| test.c:184:13:184:18 | p | semmle.label | p |
121+
| test.c:187:32:187:32 | p | semmle.label | p |
122+
| test.c:187:47:187:51 | ... + ... | semmle.label | ... + ... |
123+
| test.c:189:32:189:32 | p | semmle.label | p |
124+
| test.c:189:47:189:59 | ... + ... | semmle.label | ... + ... |
125+
| test.c:189:47:189:59 | ... + ... | semmle.label | ... + ... |
126+
| test.c:189:51:189:59 | ... / ... | semmle.label | ... / ... |
127+
| test.c:193:13:193:21 | ... / ... | semmle.label | ... / ... |
128+
| test.c:197:23:197:31 | ... / ... | semmle.label | ... / ... |
129+
| test.c:199:25:199:33 | ... / ... | semmle.label | ... / ... |
130+
| test.c:203:19:203:27 | ... / ... | semmle.label | ... / ... |
131+
| test.c:203:19:203:27 | ... / ... | semmle.label | ... / ... |
132+
| test.c:205:21:205:31 | ... + ... | semmle.label | ... + ... |
133+
| test.c:205:21:205:31 | ... + ... | semmle.label | ... + ... |
134+
| test.c:207:13:207:21 | middleNaN | semmle.label | middleNaN |
135+
| test.c:209:23:209:31 | middleNaN | semmle.label | middleNaN |
136+
subpaths

c/common/test/rules/misuseofnanfloatingpointvalue/test.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ void f1(float p1) {
160160

161161
(int)pow(2, p1); // COMPLIANT: likely to be Infinity
162162
(int)pow(2, sin(p1)); // COMPLIANT: not likely to be Infinity
163-
(int)(1 /
164-
sin(p1)); // COMPLIANT: possible infinity from zero in denominator
165-
(int)(1 / log(p1)); // COMPLIANT: not possibly zero in denominator
166-
(int)pow(p1, p1); // NON_COMPLIANT: NaN if p1 is zero
163+
(int)(1 / sin(p1)); // COMPLIANT: possible infinity from zero in denominator
164+
(int)(1 / log(p1)); // COMPLIANT: not possibly zero in denominator
165+
(int)pow(p1, p1); // NON_COMPLIANT: NaN if p1 is zero
167166
if (p1 != 0) {
168167
(int)pow(p1, p1); // COMPLIANT: p1 is not zero
169168
}
@@ -190,8 +189,7 @@ void addInfThenCastToInt(float p) { castToInt(p + 1.0 / 0.0); }
190189
void addNaNThenCastToInt(float p) { castToInt(p + 0.0 / 0.0); }
191190

192191
void f2() {
193-
castToInt(1.0 /
194-
0.0); // COMPLIANT: Infinity flows to denominator in division
192+
castToInt(1.0 / 0.0); // COMPLIANT: Infinity flows to denominator in division
195193
castToInt(0.0 / 0.0); // COMPLIANT: NaN flows to denominator in division
196194
checkBeforeCastToInt(1.0 / 0.0); // COMPLIANT
197195
checkBeforeCastToInt(0.0 / 0.0); // COMPLIANT

cpp/common/src/codingstandards/cpp/RestrictedRangeAnalysis.qll

+3-2
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,9 @@ module RestrictedRangeAnalysis {
10931093
(
10941094
// If the expression evaluates to a constant, then there is no
10951095
// need to call getUpperBoundsImpl.
1096-
if exists(getValue(expr).toFloat()) and
1097-
not getValue(expr) = "NaN"
1096+
if
1097+
exists(getValue(expr).toFloat()) and
1098+
not getValue(expr) = "NaN"
10981099
then result = getValue(expr).toFloat()
10991100
else (
11001101
// Some of the bounds computed by `getUpperBoundsImpl`

0 commit comments

Comments
 (0)