C++: Add test demonstrating the false positive

This commit is contained in:
Mathias Vorreiter Pedersen
2019-12-27 14:25:30 +01:00
parent 7e84453ec9
commit cfb839a8f9
2 changed files with 15 additions and 0 deletions

View File

@@ -92,3 +92,13 @@ void use_printf(float f, double d)
size_t three_chars(unsigned char a, unsigned char b, unsigned char c) {
return a * b * c; // at most 16581375
}
void g(unsigned char a, unsigned char b, unsigned char b2, int c) {
unsigned long d, e, f, g, h;
d = (a + 1) * (b + 1); // GOOD [FALSE POSITIVE]
e = (c + 1) * (b + 1); // BAD
h = (a + 1) * (b + 1) * (b2 + 1); // GOOD [FALSE POSITIVE]
f = (a + (a + 1)) * (b + 1); // GOOD [FALSE POSITIVE]
g = (c + (a + 1)) * (b + 1); // BAD
}

View File

@@ -7,3 +7,8 @@
| IntMultToLong.c:61:23:61:33 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
| IntMultToLong.c:63:23:63:40 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
| IntMultToLong.c:75:9:75:13 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'size_t'. |
| IntMultToLong.c:98:9:98:25 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
| IntMultToLong.c:99:9:99:25 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
| IntMultToLong.c:100:9:100:36 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
| IntMultToLong.c:102:9:102:31 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
| IntMultToLong.c:103:9:103:31 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |