File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
cpp/ql/test/query-tests/JPL_C/LOC-4/Rule 30/FunctionPointerConversions Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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. |
Original file line number Diff line number Diff line change 1+ JPL_C/LOC-4/Rule 30/FunctionPointerConversions.ql
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments