File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
c/misra/test/rules/RULE-12-5 Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments