Merge pull request #532 from geoffw0/query-tags-3

CPP: Query Tags 3 (JPL_C queries)
This commit is contained in:
Jonas Jensen
2018-11-30 15:45:01 +01:00
committed by GitHub
49 changed files with 216 additions and 24 deletions

View File

@@ -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. |

View File

@@ -0,0 +1 @@
JPL_C/LOC-4/Rule 29/NonConstFunctionPointer.ql

View File

@@ -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]
}

View File

@@ -0,0 +1,6 @@
| test.c:11:16:11:23 | & ... | Function pointer converted to int *, which is not an integral type. |
| test.c:12:18:12:25 | & ... | Function pointer converted to void *, which is not an integral type. |
| test.c:17:11:17:17 | funPtr1 | Function pointer converted to int *, which is not an integral type. |
| test.c:18:12:18:18 | funPtr1 | Function pointer converted to void *, which is not an integral type. |
| test.c:29:18:29:24 | funPtr1 | Function pointer converted to int *, which is not an integral type. |
| test.c:30:20:30:26 | funPtr1 | Function pointer converted to void *, which is not an integral type. |

View File

@@ -0,0 +1 @@
JPL_C/LOC-4/Rule 30/FunctionPointerConversions.ql

View File

@@ -0,0 +1,32 @@
// test.c
void myFunc1();
typedef void (*voidFunPtr)();
void test()
{
void (*funPtr1)() = &myFunc1; // GOOD
voidFunPtr funPtr2 = &myFunc1; // GOOD
int *intPtr = &myFunc1; // BAD (function pointer -> int pointer)
void *voidPtr = &myFunc1; // BAD (function pointer -> void pointer)
int i = &myFunc1; // GOOD (permitted)
funPtr1 = funPtr1; // GOOD
funPtr2 = funPtr1; // GOOD
intPtr = funPtr1; // BAD (function pointer -> int pointer)
voidPtr = funPtr1; // BAD (function pointer -> void pointer)
i = funPtr1; // GOOD (permitted)
funPtr1 = funPtr2; // GOOD
funPtr2 = funPtr2; // GOOD
intPtr = funPtr2; // BAD (function pointer -> int pointer) [NOT DETECTED]
voidPtr = funPtr2; // BAD (function pointer -> void pointer) [NOT DETECTED]
i = funPtr2; // GOOD (permitted)
funPtr1 = (void (*)())funPtr1; // GOOD
funPtr2 = (voidFunPtr)funPtr1; // GOOD
intPtr = (int *)funPtr1; // BAD (function pointer -> int pointer)
voidPtr = (void *)funPtr1; // BAD (function pointer -> void pointer)
i = (int)funPtr1; // GOOD (permitted)
}