зеркало из https://github.com/github/codeql.git
CPP: Add a test of NonConstFunctionPointer.ql.
This commit is contained in:
Родитель
17560cf92e
Коммит
5d8e34a55f
|
@ -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]
|
||||
}
|
Загрузка…
Ссылка в новой задаче