Skip to content

Commit c6682eb

Browse files
committed
Remove file staged by mistake and really add test.c
1 parent d5259e2 commit c6682eb

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

.codeql-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

c/misra/test/rules/RULE-12-5/test.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdint.h>
2+
3+
void sample(int32_t nums[4], const char string[], int32_t x) {
4+
for (int i = 0;
5+
i < sizeof(nums) / // NON_COMPLIANT: `sizeof` directly invoked on `nums`
6+
sizeof(int32_t);
7+
i++) {
8+
printf("%d\n", nums[i]);
9+
}
10+
11+
for (int i = 0;
12+
i < sizeof(string) / // NON_COMPLIANT: directly invoked on `string`
13+
sizeof(char);
14+
i++) {
15+
printf("%c", string[i]);
16+
}
17+
18+
printf("%d\n", sizeof(x)); // COMPLIANT: `x` not a array type parameter
19+
20+
char local_string[5] = "abcd";
21+
printf(
22+
"%d\n",
23+
sizeof(
24+
local_string)); // COMPLIANT: `local_string` not a function parameter
25+
26+
const char *string = (const char *)string;
27+
28+
for (int i = 0;
29+
i < sizeof(string) / // COMPLIANT: not a parameter access anymore, now a
30+
// const char* variable declared in the body
31+
sizeof(char);
32+
i++) {
33+
printf("%c", string[i]);
34+
}
35+
}

0 commit comments

Comments
 (0)