Skip to content

Commit 91a9a7e

Browse files
authored
Create test.cpp
1 parent dc09c92 commit 91a9a7e

File tree

1 file changed

+59
-0
lines changed
  • cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/IfStatementAdditionOverflow

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
int getAnInt();
3+
double getADouble();
4+
unsigned short getAnUnsignedShort();
5+
6+
void test()
7+
{
8+
int a = getAnInt();
9+
int b = getAnInt();
10+
int c = getAnInt();
11+
int x = getAnInt();
12+
int y = getAnInt();
13+
int d = getADouble();
14+
int a1 = getAnUnsignedShort();
15+
int b1 = getAnUnsignedShort();
16+
int c1 = getAnUnsignedShort();
17+
18+
if (a+b>c) a = c-b; // BAD
19+
if (a+b>c) { a = c-b; } // BAD
20+
if (b+a>c) a = c-b; // BAD
21+
if (b+a>c) { a = c-b; } // BAD
22+
if (c>a+b) a = c-b; // BAD
23+
if (c>a+b) { a = c-b; } // BAD
24+
if (c>b+a) a = c-b; // BAD
25+
if (c>b+a) { a = c-b; } // BAD
26+
27+
if (a+b>=c) a = c-b; // BAD
28+
if (a+b>=c) { a = c-b; } // BAD
29+
if (b+a>=c) a = c-b; // BAD
30+
if (b+a>=c) { a = c-b; } // BAD
31+
if (c>=a+b) a = c-b; // BAD
32+
if (c>=a+b) { a = c-b; } // BAD
33+
if (c>=b+a) a = c-b; // BAD
34+
if (c>=b+a) { a = c-b; } // BAD
35+
36+
if (a+b<c) a = c-b; // BAD
37+
if (a+b<c) { a = c-b; } // BAD
38+
if (b+a<c) a = c-b; // BAD
39+
if (b+a<c) { a = c-b; } // BAD
40+
if (c<a+b) a = c-b; // BAD
41+
if (c<a+b) { a = c-b; } // BAD
42+
if (c<b+a) a = c-b; // BAD
43+
if (c<b+a) { a = c-b; } // BAD
44+
45+
if (a+b<=c) a = c-b; // BAD
46+
if (a+b<=c) { a = c-b; } // BAD
47+
if (b+a<=c) a = c-b; // BAD
48+
if (b+a<=c) { a = c-b; } // BAD
49+
if (c<=a+b) a = c-b; // BAD
50+
if (c<=a+b) { a = c-b; } // BAD
51+
if (c<=b+a) a = c-b; // BAD
52+
if (c<=b+a) { a = c-b; } // BAD
53+
54+
if (a+b>d) a = d-b; // GOOD
55+
if (a+(-x)>c) a = c-(-y); // GOOD
56+
if (a+b>c) { b++; a = c-b; } // GOOD
57+
if (a+d>c) a = c-d; // GOOD
58+
if (a1+b1>c1) a1 = c1-b1; // GOOD
59+
}

0 commit comments

Comments
 (0)