@@ -130,15 +130,15 @@ void stack_allocated_multi_dimensional_array_access(int array[2][3]) {
130130 int valid11 = array[0 ][0 ]; // COMPLIANT: pointer is within boundary
131131 int valid12 = array[0 ][1 ]; // COMPLIANT: pointer is within boundary
132132 int valid13 = array[0 ][2 ]; // COMPLIANT: pointer is within boundary
133- int valid13 = array[0 ][3 ]; // COMPLIANT: pointer points one beyond the last
133+ int valid14 = array[0 ][3 ]; // COMPLIANT: pointer points one beyond the last
134134 // element, but non-compliant to Rule 4.1.3
135135 int invalid1 = array[0 ][4 ]; // NON_COMPLIANT: pointer points more than one
136136 // beyond the last element
137137
138138 int valid21 = array[1 ][0 ]; // COMPLIANT: pointer is within boundary
139139 int valid22 = array[1 ][1 ]; // COMPLIANT: pointer is within boundary
140140 int valid23 = array[1 ][2 ]; // COMPLIANT: pointer is within boundary
141- int valid13 = array[1 ][3 ]; // COMPLIANT: pointer points one beyond the last
141+ int valid24 = array[1 ][3 ]; // COMPLIANT: pointer points one beyond the last
142142 // element, but non-compliant to Rule 4.1.3
143143 int invalid2 = array[1 ][4 ]; // NON_COMPLIANT: pointer points more than one
144144 // beyond the last element
@@ -150,6 +150,21 @@ void stack_allocated_multi_dimensional_array_access(int array[2][3]) {
150150 // beyond the last element
151151}
152152
153+ void row_reader (int row[3 ]) {
154+ int x1 = row[0 ]; // COMPLIANT: pointer is within boundary
155+ int x2 = row[1 ]; // COMPLIANT: pointer is within boundary
156+ int x3 = row[2 ]; // COMPLIANT[FALSE_POSITIVE]: pointer is within boundary
157+ int x4 = row[3 ]; // COMPLIANT[FALSE_POSITIVE]: pointer points one beyond the last
158+ // element, but non-compliant to Rule 4.1.3
159+ int x5 = row[4 ]; // NON_COMPLIANT: pointer points more than one
160+ // beyond the last element
161+ }
162+
163+ void stack_allocated_multi_dimensional_array_access2 (int array[2 ][3 ]) {
164+ row_reader (array[0 ]); // COMPLIANT: pointer is within boundary
165+ row_reader (array[1 ]); // COMPLIANT: pointer is within boundary
166+ }
167+
153168void stack_allocated_multi_dimensional_pointer_arithmetic (int array[2 ][3 ]) {
154169 int valid111 = *(*(array + 0 ) + 0 ); // COMPLIANT: pointer is within boundary
155170 int valid112 = *(
@@ -509,11 +524,13 @@ int main(int argc, char *argv[]) {
509524 int stack_multi_dimensional_array[2 ][3 ] = {{1 , 2 , 3 }, {4 , 5 , 6 }};
510525
511526 /* 4. Multi-dimensional array initialized on the heap */
512- int (*heap_multi_dimensional_array)[3 ] = (int (*)[3 ])malloc (sizeof (int [2 ][3 ]));
527+ int (*heap_multi_dimensional_array)[3 ] = (int (*)[3 ])malloc (sizeof (int [2 ][3 ]));
513528
514529 stack_allocated_multi_dimensional_array_access (stack_multi_dimensional_array);
515530 stack_allocated_multi_dimensional_pointer_arithmetic (
516531 stack_multi_dimensional_array);
532+ stack_allocated_multi_dimensional_array_access2 (
533+ stack_multi_dimensional_array);
517534
518535 return 0 ;
519536}
0 commit comments