Skip to content

Commit e6dddd9

Browse files
committed
CPP: Add a test of FunctionPointerConversions.ql.
1 parent 5d8e34a commit e6dddd9

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| test.c:11:16:11:23 | & ... | Function pointer converted to int *, which is not an integral type. |
2+
| test.c:12:18:12:25 | & ... | Function pointer converted to void *, which is not an integral type. |
3+
| test.c:17:11:17:17 | funPtr1 | Function pointer converted to int *, which is not an integral type. |
4+
| test.c:18:12:18:18 | funPtr1 | Function pointer converted to void *, which is not an integral type. |
5+
| test.c:29:18:29:24 | funPtr1 | Function pointer converted to int *, which is not an integral type. |
6+
| test.c:30:20:30:26 | funPtr1 | Function pointer converted to void *, which is not an integral type. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JPL_C/LOC-4/Rule 30/FunctionPointerConversions.ql
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// test.c
2+
3+
void myFunc1();
4+
5+
typedef void (*voidFunPtr)();
6+
7+
void test()
8+
{
9+
void (*funPtr1)() = &myFunc1; // GOOD
10+
voidFunPtr funPtr2 = &myFunc1; // GOOD
11+
int *intPtr = &myFunc1; // BAD (function pointer -> int pointer)
12+
void *voidPtr = &myFunc1; // BAD (function pointer -> void pointer)
13+
int i = &myFunc1; // GOOD (permitted)
14+
15+
funPtr1 = funPtr1; // GOOD
16+
funPtr2 = funPtr1; // GOOD
17+
intPtr = funPtr1; // BAD (function pointer -> int pointer)
18+
voidPtr = funPtr1; // BAD (function pointer -> void pointer)
19+
i = funPtr1; // GOOD (permitted)
20+
21+
funPtr1 = funPtr2; // GOOD
22+
funPtr2 = funPtr2; // GOOD
23+
intPtr = funPtr2; // BAD (function pointer -> int pointer) [NOT DETECTED]
24+
voidPtr = funPtr2; // BAD (function pointer -> void pointer) [NOT DETECTED]
25+
i = funPtr2; // GOOD (permitted)
26+
27+
funPtr1 = (void (*)())funPtr1; // GOOD
28+
funPtr2 = (voidFunPtr)funPtr1; // GOOD
29+
intPtr = (int *)funPtr1; // BAD (function pointer -> int pointer)
30+
voidPtr = (void *)funPtr1; // BAD (function pointer -> void pointer)
31+
i = (int)funPtr1; // GOOD (permitted)
32+
}

0 commit comments

Comments
 (0)