Skip to content

Commit 6552c84

Browse files
committed
C++: Fix BMN issue in cpp/integer-multiplication-cast-to-long.
1 parent 00d8a10 commit 6552c84

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ where
218218
// only report if we cannot prove that the result of the
219219
// multiplication will be less (resp. greater) than the
220220
// maximum (resp. minimum) number we can compute.
221-
overflows(me, t1)
221+
overflows(me, t1) and
222+
// exclude cases where the expression type may not have been extracted accurately
223+
not me.getParent().(Call).getTarget().hasAmbiguousReturnType()
222224
select me,
223225
"Multiplication result may overflow '" + me.getType().toString() + "' before it is converted to '"
224226
+ me.getFullyConverted().getType().toString() + "'."

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/IntMultToLong/Buildless.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ void test_float_double1(float f, double d) {
66
double r3 = f * f; // BAD
77
double r4 = f * d; // GOOD
88

9-
float f1 = fabsf(f * f); // GOOD [FALSE POSITIVE]
9+
float f1 = fabsf(f * f); // GOOD
1010
float f2 = fabsf(f * d); // GOOD
11-
double f3 = fabs(f * f); // BAD
11+
double f3 = fabs(f * f); // BAD [NOT DETECTED]
1212
double f4 = fabs(f * d); // GOOD
1313
}
1414

@@ -23,6 +23,6 @@ void test_float_double2(float f, double d) {
2323

2424
float f1 = fabsf(f * f); // GOOD
2525
float f2 = fabsf(f * d); // GOOD
26-
double f3 = fabs(f * f); // BAD
26+
double f3 = fabs(f * f); // BAD [NOT DETECTED]
2727
double f4 = fabs(f * d); // GOOD
2828
}

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/IntMultToLong/IntMultToLong.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
| Buildless.c:6:17:6:21 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
2-
| Buildless.c:9:22:9:26 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
3-
| Buildless.c:11:22:11:26 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
42
| Buildless.c:21:17:21:21 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
5-
| Buildless.c:26:22:26:26 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
63
| IntMultToLong.c:4:10:4:14 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
74
| IntMultToLong.c:7:16:7:20 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
85
| IntMultToLong.c:18:19:18:23 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |

0 commit comments

Comments
 (0)