Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfb839a

Browse files
committed
C++: Add test demonstrating the false positive
1 parent 7e84453 commit cfb839a

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,13 @@ void use_printf(float f, double d)
9292
size_t three_chars(unsigned char a, unsigned char b, unsigned char c) {
9393
return a * b * c; // at most 16581375
9494
}
95+
96+
void g(unsigned char a, unsigned char b, unsigned char b2, int c) {
97+
unsigned long d, e, f, g, h;
98+
d = (a + 1) * (b + 1); // GOOD [FALSE POSITIVE]
99+
e = (c + 1) * (b + 1); // BAD
100+
h = (a + 1) * (b + 1) * (b2 + 1); // GOOD [FALSE POSITIVE]
101+
102+
f = (a + (a + 1)) * (b + 1); // GOOD [FALSE POSITIVE]
103+
g = (c + (a + 1)) * (b + 1); // BAD
104+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
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:98:9:98:25 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
11+
| IntMultToLong.c:99:9:99:25 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
12+
| IntMultToLong.c:100:9:100:36 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
13+
| IntMultToLong.c:102:9:102:31 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
14+
| IntMultToLong.c:103:9:103:31 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |

0 commit comments

Comments
 (0)