Compare commits

...

2 Commits

Author SHA1 Message Date
Calum Grant
60076dc8a8 C++: Remove potential FPs from cpp/integer-multiplication-cast-to-long in BMN 2025-01-23 19:45:44 +00:00
Calum Grant
d3e469f989 C++: Test for buildless IntMultToLong 2025-01-23 16:50:03 +00:00
4 changed files with 21 additions and 1 deletions

View File

@@ -177,6 +177,12 @@ predicate overflows(MulExpr me, Type t) {
)
}
predicate buildModeNoneIntLongConversion(IntType argType, LongType resultType) {
exists(argType) and
exists(resultType) and
exists(Compilation c | c.buildModeNone())
}
from MulExpr me, Type t1, Type t2
where
t1 = me.getType().getUnderlyingType() and
@@ -218,7 +224,10 @@ where
// only report if we cannot prove that the result of the
// multiplication will be less (resp. greater) than the
// maximum (resp. minimum) number we can compute.
overflows(me, t1)
overflows(me, t1) and
// In build mode none, many conversions from integer to long are caused by incorrect types,
// so exclude those results
not buildModeNoneIntLongConversion(t1, t2)
select me,
"Multiplication result may overflow '" + me.getType().toString() + "' before it is converted to '"
+ me.getFullyConverted().getType().toString() + "'."

View File

@@ -0,0 +1,10 @@
// semmle-extractor-options: --build-mode none
int f();
void test() {
int i = f();
unsigned u = i;
long j = i * i; // GOOD: build mode none
unsigned long k = u * u; // GOOD: build mode none
}

View File

@@ -0,0 +1 @@
Likely Bugs/Arithmetic/IntMultToLong.ql