Skip to content

Commit 5d8e34a

Browse files
committed
CPP: Add a test of NonConstFunctionPointer.ql.
1 parent 17560cf commit 5d8e34a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:18:2:18:10 | call to expression | This call does not go through a const function pointer. |
2+
| test.c:19:2:19:10 | call to expression | This call does not go through a const function pointer. |
3+
| test.c:20:2:20:10 | call to expression | This call does not go through a const function pointer. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JPL_C/LOC-4/Rule 29/NonConstFunctionPointer.ql
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// test.c
2+
3+
void myFunc1();
4+
void myFunc2();
5+
6+
typedef void (*voidFunPointer)();
7+
8+
void test()
9+
{
10+
void (*funPtr1)() = &myFunc1;
11+
const void (*funPtr2)() = &myFunc1;
12+
const voidFunPointer funPtr3 = &myFunc1;
13+
14+
funPtr1 = &myFunc2;
15+
funPtr2 = &myFunc2;
16+
//funPtr3 = &myFunc2; --- this would be a compilation error
17+
18+
funPtr1(); // BAD
19+
funPtr2(); // BAD
20+
funPtr3(); // GOOD [FALSE POSITIVE]
21+
}

0 commit comments

Comments
 (0)