File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
src/Likely Bugs/Arithmetic
test/query-tests/Likely Bugs/Arithmetic/IntMultToLong Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -21,17 +21,19 @@ import semmle.code.cpp.controlflow.SSA
2121/**
2222 * Holds if `e` is either:
2323 * - a constant
24+ * - a char-typed expression, meaning it's a small number
2425 * - an array access to an array of constants
2526 * - flows from one of the above
2627 * In these cases the value of `e` is likely to be small and
2728 * controlled, so we consider it less likely to cause an overflow.
2829 */
29- predicate effectivelyConstant ( Expr e ) {
30+ predicate likelySmall ( Expr e ) {
3031 e .isConstant ( ) or
32+ e .getType ( ) .getSize ( ) <= 1 or
3133 e .( ArrayExpr ) .getArrayBase ( ) .getType ( ) .( ArrayType ) .getBaseType ( ) .isConst ( ) or
3234 exists ( SsaDefinition def , Variable v |
3335 def .getAUse ( v ) = e and
34- effectivelyConstant ( def .getDefiningValue ( v ) )
36+ likelySmall ( def .getDefiningValue ( v ) )
3537 )
3638}
3739
@@ -56,7 +58,7 @@ int getEffectiveMulOperands(MulExpr me) {
5658 result = count ( Expr op |
5759 op = getMulOperand * ( me ) and
5860 not op instanceof MulExpr and
59- not effectivelyConstant ( op )
61+ not likelySmall ( op )
6062 )
6163}
6264
Original file line number Diff line number Diff line change @@ -88,3 +88,7 @@ void use_printf(float f, double d)
8888 // ^ there's a float -> double varargs promotion here, but it's unlikely that the author anticipates requiring a double
8989 printf ("%f" , d * d ); // safe
9090}
91+
92+ size_t three_chars (unsigned char a , unsigned char b , unsigned char c ) {
93+ return a * b * c ; // at most 16581375
94+ }
You can’t perform that action at this time.
0 commit comments