Skip to content

Commit 8c733fd

Browse files
authored
Merge pull request #1537 from geoffw0/add-tests
CPP: Add some tests
2 parents b51c78a + 8ce6822 commit 8c733fd

File tree

13 files changed

+154
-2
lines changed

13 files changed

+154
-2
lines changed

cpp/ql/src/Likely Bugs/Memory Management/Padding/NonPortablePrintf.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ where (
8484
and not arg.isAffectedByMacro()
8585
and size32 = ilp32.paddedSize(actual) and size64 = lp64.paddedSize(actual)
8686
and size64 != size32
87-
select arg, "This argument should be of type "+expected.getName()+" but is of type "+actual.getName() +
88-
" (which changes size from " + size32 + " to " + size64 + " on 64-bit systems)."
87+
select arg, "This argument should be of type '" + expected.getName() + "' but is of type '" + actual.getName() +
88+
"' (which changes size from " + size32 + " to " + size64 + " on 64-bit systems)."
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
| test.cpp:2:6:2:10 | func1 | | isNoExcept |
2+
| test.cpp:3:6:3:10 | func2 | | |
3+
| test.cpp:4:6:4:10 | func3 | | |
4+
| test.cpp:5:6:5:10 | func4 | | |
5+
| test.cpp:6:6:6:10 | func5 | | |
6+
| test.cpp:8:6:8:10 | func6 | | isNoThrow |
7+
| test.cpp:9:6:9:10 | func7 | int | |
8+
| test.cpp:11:6:11:10 | func8 | char, int | |
9+
| test.cpp:15:7:15:7 | operator= | | isNoThrow |
10+
| test.cpp:15:7:15:7 | operator= | | isNoThrow |
11+
| test.cpp:17:7:17:11 | func9 | | isNoThrow |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import cpp
2+
3+
string describe(Function f) {
4+
(
5+
f.isNoThrow() and
6+
result = "isNoThrow"
7+
) or (
8+
f.isNoExcept() and
9+
result = "isNoExcept"
10+
)
11+
}
12+
13+
from Function f
14+
where exists(f.getFile())
15+
select f, concat(f.getAThrownType().toString(), ", "), concat(describe(f), ", ")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
void func1() noexcept;
3+
void func2() noexcept(true);
4+
void func3() noexcept(false);
5+
void func4() noexcept(func1);
6+
void func5(void param() noexcept);
7+
8+
void func6() throw();
9+
void func7() throw(int);
10+
void func8() throw(char, int);
11+
void func8() throw(char, int)
12+
{
13+
}
14+
15+
class c
16+
{
17+
void func9() throw();
18+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:17:8:17:12 | test4 | test4 includes 0 bits of padding on ILP32, but 32 bits on LP64. |
2+
| test.cpp:29:8:29:12 | test6 | test6 includes 0 bits of padding on ILP32, but 32 bits on LP64. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Memory Management/Padding/More64BitWaste.ql
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
struct test1
3+
{
4+
int x;
5+
};
6+
7+
struct test2
8+
{
9+
int x, y;
10+
};
11+
12+
struct test3
13+
{
14+
int x, y, z;
15+
};
16+
17+
struct test4 // BAD
18+
{
19+
int a;
20+
long long b;
21+
};
22+
23+
struct test5
24+
{
25+
long long a;
26+
int b;
27+
};
28+
29+
struct test6 // BAD
30+
{
31+
char as[4];
32+
long long b;
33+
};
34+
35+
struct test7
36+
{
37+
char as[8];
38+
long long b;
39+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.cpp:10:17:10:17 | l | This argument should be of type 'int' but is of type 'long' (which changes size from 32 to 64 on 64-bit systems). |
2+
| test.cpp:13:17:13:19 | ptr | This argument should be of type 'int' but is of type 'void *' (which changes size from 32 to 64 on 64-bit systems). |
3+
| test.cpp:14:17:14:19 | ptr | This argument should be of type 'unsigned int' but is of type 'void *' (which changes size from 32 to 64 on 64-bit systems). |
4+
| test.cpp:15:17:15:19 | ptr | This argument should be of type 'unsigned int' but is of type 'void *' (which changes size from 32 to 64 on 64-bit systems). |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Memory Management/Padding/NonPortablePrintf.ql
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
int printf(const char *format, ...);
3+
4+
void test1()
5+
{
6+
long l;
7+
void *ptr;
8+
9+
printf("%ld\n", l); // GOOD
10+
printf("%d\n", l); // BAD
11+
12+
printf("%p\n", ptr); // GOOD
13+
printf("%d\n", ptr); // BAD
14+
printf("%u\n", ptr); // BAD
15+
printf("%x\n", ptr); // BAD
16+
}

0 commit comments

Comments
 (0)