Skip to content

Commit

Permalink
Format test, commit user README changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRFairhurst committed Sep 27, 2024
1 parent 722dc6a commit c9ced08
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
| test.c:15:25:15:29 | func2 | The address of function func2 is taken without the & operator. |
| test.c:16:27:16:31 | func3 | The address of function func3 is taken without the & operator. |
| test.c:22:16:22:20 | func1 | The address of function func1 is taken without the & operator. |
| test.c:39:5:39:9 | func1 | The address of function func1 is taken without the & operator. |
| test.c:40:5:40:9 | func2 | The address of function func2 is taken without the & operator. |
| test.c:48:7:48:11 | func1 | The address of function func1 is taken without the & operator. |
| test.c:49:7:49:11 | func2 | The address of function func2 is taken without the & operator. |
| test.c:58:15:58:19 | func1 | The address of function func1 is taken without the & operator. |
| test.c:59:23:59:27 | func2 | The address of function func2 is taken without the & operator. |
| test.c:60:15:60:19 | func1 | The address of function func1 is taken without the & operator. |
| test.c:60:22:60:26 | func2 | The address of function func2 is taken without the & operator. |
| test.c:68:13:68:17 | func1 | The address of function func1 is taken without the & operator. |
| test.c:69:14:69:18 | func1 | The address of function func1 is taken without the & operator. |
| test.c:70:14:70:18 | func1 | The address of function func1 is taken without the & operator. |
| test.c:72:20:72:24 | func1 | The address of function func1 is taken without the & operator. |
| test.c:14:25:14:29 | func2 | The address of function func2 is taken without the & operator. |
| test.c:15:27:15:31 | func3 | The address of function func3 is taken without the & operator. |
| test.c:21:12:21:16 | func1 | The address of function func1 is taken without the & operator. |
| test.c:38:3:38:7 | func1 | The address of function func1 is taken without the & operator. |
| test.c:39:3:39:7 | func2 | The address of function func2 is taken without the & operator. |
| test.c:47:5:47:9 | func1 | The address of function func1 is taken without the & operator. |
| test.c:48:5:48:9 | func2 | The address of function func2 is taken without the & operator. |
| test.c:57:13:57:17 | func1 | The address of function func1 is taken without the & operator. |
| test.c:58:21:58:25 | func2 | The address of function func2 is taken without the & operator. |
| test.c:59:13:59:17 | func1 | The address of function func1 is taken without the & operator. |
| test.c:59:20:59:24 | func2 | The address of function func2 is taken without the & operator. |
| test.c:67:11:67:15 | func1 | The address of function func1 is taken without the & operator. |
| test.c:68:12:68:16 | func1 | The address of function func1 is taken without the & operator. |
| test.c:69:12:69:16 | func1 | The address of function func1 is taken without the & operator. |
| test.c:71:18:71:22 | func1 | The address of function func1 is taken without the & operator. |
172 changes: 85 additions & 87 deletions c/misra/test/rules/RULE-17-12/test.c
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
void func1() {}
void func2(int x, char* y) {}
void func2(int x, char *y) {}

typedef struct {} s;
typedef struct {
} s;

int func3() {
return 0;
}
int func3() { return 0; }

typedef void (*func_ptr_t1)();
typedef void (*func_ptr_t2)(int x, char* y);
typedef void (*func_ptr_t2)(int x, char *y);
typedef s (*func_ptr_t3)();

func_ptr_t1 func_ptr1 = &func1; // COMPLIANT
func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT
func_ptr_t1 func_ptr1 = &func1; // COMPLIANT
func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT
func_ptr_t3 func_ptr3 = &(func3); // NON-COMPLIANT

void take_func(func_ptr_t1 f1, func_ptr_t2 f2);

func_ptr_t1 returns_func(int x) {
if (x == 0) {
return func1; // NON-COMPLIANT
} else if (x == 1) {
return &func1; // COMPLIANT
}
if (x == 0) {
return func1; // NON-COMPLIANT
} else if (x == 1) {
return &func1; // COMPLIANT
}

return returns_func(0); // COMPLIANT
return returns_func(0); // COMPLIANT
}

#define MACRO_IDENTITY(f) (f)
Expand All @@ -33,77 +32,76 @@ func_ptr_t1 returns_func(int x) {
#define MACRO_INVOKE_AND_USE_AS_TOKEN(f) f(0, #f)

void test() {
func1(); // COMPLIANT
func2(1, "hello"); // COMPLIANT

func1; // NON-COMPLIANT
func2; // NON-COMPLIANT

&func1; // COMPLIANT
&func2; // COMPLIANT

(func1)(); // COMPLIANT
(func2)(1, "hello"); // COMPLIANT

&(func1); // NON-COMPLIANT
&(func2); // NON-COMPLIANT

(&func1)(); // COMPLIANT
(&func2)(1, "hello"); // COMPLIANT

(func1()); // COMPLIANT
(func2(1, "hello")); // COMPLIANT

take_func(&func1, &func2); // COMPLIANT
take_func(func1, &func2); // NON-COMPLIANT
take_func(&func1, func2); // NON-COMPLIANT
take_func(func1, func2); // NON-COMPLIANT

returns_func(0); // COMPLIANT
returns_func(0)(); // COMPLIANT
(returns_func(0))(); // COMPLIANT

(void*) &func1; // COMPLIANT
(void*) (&func1); // COMPLIANT
(void*) func1; // NON-COMPLIANT
(void*) (func1); // NON-COMPLIANT
((void*) func1); // NON-COMPLIANT

MACRO_IDENTITY(func1); // NON-COMPLIANT
MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_IDENTITY(&func1); // COMPLIANT
MACRO_IDENTITY(&func1)(); // COMPLIANT

MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT

MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT

// Function pointers are exempt from this rule.
func_ptr1(); // COMPLIANT
func_ptr2(1, "hello"); // COMPLIANT
func_ptr1; // COMPLIANT
func_ptr2; // COMPLIANT
&func_ptr1; // COMPLIANT
&func_ptr2; // COMPLIANT
(func_ptr1)(); // COMPLIANT
(func_ptr2)(1, "hello"); // COMPLIANT
(*func_ptr1)(); // COMPLIANT
(*func_ptr2)(1, "hello"); // COMPLIANT
take_func(func_ptr1, func_ptr2); // COMPLIANT
(void*) func_ptr1; // COMPLIANT
(void*) &func_ptr1; // COMPLIANT
(void*) (&func_ptr1); // COMPLIANT
(void*) func_ptr1; // COMPLIANT
(void*) (func_ptr1); // COMPLIANT
((void*) func_ptr1); // COMPLIANT
MACRO_IDENTITY(func_ptr1); // COMPLIANT
MACRO_IDENTITY(func_ptr1)(); // COMPLIANT
MACRO_IDENTITY(&func_ptr1); // COMPLIANT
(*MACRO_IDENTITY(&func_ptr1))(); // COMPLIANT
MACRO_INVOKE_RISKY(func_ptr3); // COMPLIANT
MACRO_INVOKE_IMPROVED(func_ptr3); // COMPLIANT
MACRO_INVOKE_IMPROVED(*&func_ptr3); // COMPLIANT

func1(); // COMPLIANT
func2(1, "hello"); // COMPLIANT

func1; // NON-COMPLIANT
func2; // NON-COMPLIANT

&func1; // COMPLIANT
&func2; // COMPLIANT

(func1)(); // COMPLIANT
(func2)(1, "hello"); // COMPLIANT

&(func1); // NON-COMPLIANT
&(func2); // NON-COMPLIANT

(&func1)(); // COMPLIANT
(&func2)(1, "hello"); // COMPLIANT

(func1()); // COMPLIANT
(func2(1, "hello")); // COMPLIANT

take_func(&func1, &func2); // COMPLIANT
take_func(func1, &func2); // NON-COMPLIANT
take_func(&func1, func2); // NON-COMPLIANT
take_func(func1, func2); // NON-COMPLIANT

returns_func(0); // COMPLIANT
returns_func(0)(); // COMPLIANT
(returns_func(0))(); // COMPLIANT

(void *)&func1; // COMPLIANT
(void *)(&func1); // COMPLIANT
(void *)func1; // NON-COMPLIANT
(void *)(func1); // NON-COMPLIANT
((void *)func1); // NON-COMPLIANT

MACRO_IDENTITY(func1); // NON-COMPLIANT
MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_IDENTITY(&func1); // COMPLIANT
MACRO_IDENTITY (&func1)(); // COMPLIANT

MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE]
MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT

MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT

// Function pointers are exempt from this rule.
func_ptr1(); // COMPLIANT
func_ptr2(1, "hello"); // COMPLIANT
func_ptr1; // COMPLIANT
func_ptr2; // COMPLIANT
&func_ptr1; // COMPLIANT
&func_ptr2; // COMPLIANT
(func_ptr1)(); // COMPLIANT
(func_ptr2)(1, "hello"); // COMPLIANT
(*func_ptr1)(); // COMPLIANT
(*func_ptr2)(1, "hello"); // COMPLIANT
take_func(func_ptr1, func_ptr2); // COMPLIANT
(void *)func_ptr1; // COMPLIANT
(void *)&func_ptr1; // COMPLIANT
(void *)(&func_ptr1); // COMPLIANT
(void *)func_ptr1; // COMPLIANT
(void *)(func_ptr1); // COMPLIANT
((void *)func_ptr1); // COMPLIANT
MACRO_IDENTITY(func_ptr1); // COMPLIANT
MACRO_IDENTITY(func_ptr1)(); // COMPLIANT
MACRO_IDENTITY(&func_ptr1); // COMPLIANT
(*MACRO_IDENTITY(&func_ptr1))(); // COMPLIANT
MACRO_INVOKE_RISKY(func_ptr3); // COMPLIANT
MACRO_INVOKE_IMPROVED(func_ptr3); // COMPLIANT
MACRO_INVOKE_IMPROVED(*&func_ptr3); // COMPLIANT
}
2 changes: 1 addition & 1 deletion docs/user_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The datasheet _"CodeQL Coding Standards: supported rules"_, provided with each r

[^1]: AUTOSAR C++ versions R22-11, R21-11, R20-11, R19-11 and R19-03 are all identical as indicated in the document change history.
[^2]: The unimplemented supportable AUTOSAR rules are `A7-1-8` and `A8-2-1`. These rules require additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules.
[^3]: The unimplemented supportable MISRA C 2012 rules are `Rule 9.5` and `Dir 4.14`. `Rule 9.5` requires additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. `Dir 4.14` is covered by the default CodeQL queries, which identify potential security vulnerabilities caused by not validating external input.
[^3]: The unimplemented supportable MISRA C 2012 rules are `Rule 9.5`, `Rule 17.13`, and `Dir 4.14`. `Rule 9.5` and `Rule 17.13` require additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. `Dir 4.14` is covered by the default CodeQL queries, which identify potential security vulnerabilities caused by not validating external input.
[^4]: The rules 5.13.7, 19.0.1 and 19.1.2 are not planned to be implemented by CodeQL as they are compiler checked in all supported compilers.

## Supported environment
Expand Down

0 comments on commit c9ced08

Please sign in to comment.