mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
CPP: Add a test of NonConstFunctionPointer.ql.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
| test.c:18:2:18:10 | call to expression | This call does not go through a const function pointer. |
|
||||
| test.c:19:2:19:10 | call to expression | This call does not go through a const function pointer. |
|
||||
| test.c:20:2:20:10 | call to expression | This call does not go through a const function pointer. |
|
||||
@@ -0,0 +1 @@
|
||||
JPL_C/LOC-4/Rule 29/NonConstFunctionPointer.ql
|
||||
@@ -0,0 +1,21 @@
|
||||
// test.c
|
||||
|
||||
void myFunc1();
|
||||
void myFunc2();
|
||||
|
||||
typedef void (*voidFunPointer)();
|
||||
|
||||
void test()
|
||||
{
|
||||
void (*funPtr1)() = &myFunc1;
|
||||
const void (*funPtr2)() = &myFunc1;
|
||||
const voidFunPointer funPtr3 = &myFunc1;
|
||||
|
||||
funPtr1 = &myFunc2;
|
||||
funPtr2 = &myFunc2;
|
||||
//funPtr3 = &myFunc2; --- this would be a compilation error
|
||||
|
||||
funPtr1(); // BAD
|
||||
funPtr2(); // BAD
|
||||
funPtr3(); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
Reference in New Issue
Block a user