Skip to content

Commit 698570a

Browse files
committed
Add cases and relabel compliant / non-compliant
1 parent c56946a commit 698570a

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

cpp/misra/test/rules/RULE-8-7-1/test.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,23 @@ void realloc_single_dimensional_array_access(int *array) { // [3, 6]
129129
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
132-
int valid13 = array[0][2]; // COMPLIANT: pointer points one beyond the last
132+
int valid13 = array[0][2]; // COMPLIANT: pointer is within boundary
133+
int valid13 = array[0][3]; // COMPLIANT: pointer points one beyond the last
133134
// element, but non-compliant to Rule 4.1.3
134-
int invalid1 = array[0][3]; // NON_COMPLIANT: pointer points more than one
135+
int invalid1 = array[0][4]; // NON_COMPLIANT: pointer points more than one
135136
// beyond the last element
136137

137-
int valid21 = array[1][0]; // COMPLIANT: pointer is within boundary
138-
int valid22 = array[1][1]; // COMPLIANT: pointer is within boundary
139-
int valid23 = array[1][2]; // COMPLIANT: pointer points one beyond the last
140-
// element, but non-compliant to Rule 4.1.3
141-
142-
int invalid2 = array[1][3]; // NON_COMPLIANT: pointer points more than one
138+
int valid21 = array[1][0]; // COMPLIANT: pointer is within boundary
139+
int valid22 = array[1][1]; // COMPLIANT: pointer is within boundary
140+
int valid23 = array[1][2]; // COMPLIANT: pointer is within boundary
141+
int valid13 = array[1][3]; // COMPLIANT: pointer points one beyond the last
142+
// element, but non-compliant to Rule 4.1.3
143+
int invalid2 = array[1][4]; // NON_COMPLIANT: pointer points more than one
143144
// beyond the last element
144145

145-
int valid31 = array[2][0]; // COMPLIANT: pointer points one beyond the last
146-
// element, but non-compliant to Rule 4.1.3
146+
int valid31 = array[2][0]; // COMPLIANT: pointer points one beyond the last
147+
// element, but non-compliant to Rule 4.1.3
148+
147149
int invalid3 = array[3][0]; // NON_COMPLIANT: pointer points more than one
148150
// beyond the last element
149151
}
@@ -159,37 +161,35 @@ void stack_allocated_multi_dimensional_pointer_arithmetic(int array[2][3]) {
159161
int valid122 =
160162
*(*array +
161163
1); // COMPLIANT: pointer is within boundary (equivalent to the above)
162-
int valid131 =
163-
*(*(array + 0) + 2); // COMPLIANT: pointer points one beyond the last
164-
// element, but non-compliant to Rule 4.1.3
165-
int valid132 = *(
166-
*array +
167-
2); // COMPLIANT: pointer points one beyond the last
168-
// element, but non-compliant to Rule 4.1.3 (equivalent to the above)
169-
int invalid11 = *(*(array + 0) + 3); // NON_COMPLIANT: pointer points more
164+
int valid131 = *(*(array + 0) + 2); // COMPLIANT: pointer is within boundary
165+
int valid132 = *(*array + 2); // COMPLIANT: pointer is within boundary
166+
int valid141 = *(*(array + 0) + 3); // COMPLIANT: pointer points to one beyond
167+
// the last element
168+
int valid142 = *(*array + 3); // COMPLIANT: pointer points to one beyond the
169+
// last element (equivalent to the above)
170+
int invalid11 = *(*(array + 0) + 4); // NON_COMPLIANT: pointer points more
170171
// than one beyond the last element
171172
int invalid12 =
172-
*(*array + 3); // NON_COMPLIANT: pointer points more than
173+
*(*array + 4); // NON_COMPLIANT: pointer points more than
173174
// one beyond the last element (equivalent to the above)
174175

175176
int valid211 = *(*(array + 1) + 0); // COMPLIANT: pointer is within boundary
176177
int valid212 = *(
177178
*(array +
178179
1)); // COMPLIANT: pointer is within boundary (equivalent to the above)
179180
int valid22 = *(*(array + 1) + 1); // COMPLIANT: pointer is within boundary
180-
int valid23 =
181-
*(*(array + 1) + 2); // COMPLIANT: pointer points one beyond the last
182-
// element, but non-compliant to Rule 4.1.3
183-
int invalid2 = *(*(array + 1) + 3); // NON_COMPLIANT: pointer points more than
181+
int valid23 = *(*(array + 1) + 2); // COMPLIANT: pointer points one beyond the
182+
// last element
183+
int valid24 =
184+
*(*(array + 1) +
185+
3); // COMPLIANT: pointer points to one beyond the last element
186+
int invalid2 = *(*(array + 1) + 4); // NON_COMPLIANT: pointer points more than
184187
// one beyond the last element
185188

186-
int valid311 =
187-
*(*(array + 2) + 0); // COMPLIANT: pointer points one beyond the last
188-
// element, but non-compliant to Rule 4.1.3
189-
int valid312 = *(*(
190-
array +
191-
2)); // COMPLIANT: pointer points one beyond the last
192-
// element, but non-compliant to Rule 4.1.3 (equivalent to the above)
189+
int valid311 = *(*(array + 2) + 0); // COMPLIANT: pointer points one beyond
190+
// the last element
191+
int valid312 = *(*(array + 2)); // COMPLIANT: pointer points one beyond the
192+
// last element (equivalent to the above)
193193
int invalid31 = *(*(array + 3) + 0); // NON_COMPLIANT: pointer points more
194194
// than one beyond the last element
195195
int invalid32 =
@@ -509,7 +509,8 @@ int main(int argc, char *argv[]) {
509509
int stack_multi_dimensional_array[2][3] = {{1, 2, 3}, {4, 5, 6}};
510510

511511
/* 4. Multi-dimensional array initialized on the heap */
512-
int(*heap_multi_dimensional_array)[3] = (int(*)[3])malloc(sizeof(int[2][3]));
512+
int (*heap_multi_dimensional_array)[3] =
513+
(int (*)[3])malloc(sizeof(int[2][3]));
513514

514515
stack_allocated_multi_dimensional_array_access(stack_multi_dimensional_array);
515516
stack_allocated_multi_dimensional_pointer_arithmetic(

0 commit comments

Comments
 (0)