Skip to content

Commit 4d2e4c5

Browse files
committed
C++: Suppress IntMultToLong alert on char
1 parent 2b5d150 commit 4d2e4c5

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ 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
*/
2930
predicate effectivelyConstant(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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ void use_printf(float f, double d)
9090
}
9191

9292
size_t three_chars(unsigned char a, unsigned char b, unsigned char c) {
93-
return a * b * c; // at most 16581375 [FALSE POSITIVE]
93+
return a * b * c; // at most 16581375
9494
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
| IntMultToLong.c:61:23:61:33 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
88
| IntMultToLong.c:63:23:63:40 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
99
| IntMultToLong.c:75:9:75:13 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'size_t'. |
10-
| IntMultToLong.c:93:12:93:20 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'size_t'. |

0 commit comments

Comments
 (0)