Skip to content

Commit 1aa1766

Browse files
author
Nikita Kraiouchkine
committed
Add test case to ARR30-C
1 parent 76146e4 commit 1aa1766

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
| test.c:8:3:8:11 | ... + ... | Buffer accesses offset 404 which is greater than the fixed size 400 of the $@. | test.c:8:3:8:5 | arr | buffer |
22
| test.c:16:3:16:13 | ... + ... | Buffer access may be to a negative index in the buffer. | test.c:16:3:16:5 | arr | buffer |
33
| test.c:21:5:21:15 | ... + ... | Buffer access may be to a negative index in the buffer. | test.c:21:5:21:7 | arr | buffer |
4+
| test.c:41:17:41:30 | ... + ... | Buffer access may be to a negative index in the buffer. | test.c:41:17:41:22 | buffer | buffer |
5+
| test.c:45:17:45:30 | ... + ... | Buffer accesses may access up to offset 101*1 which is greater than the fixed size 100 of the $@. | test.c:45:17:45:22 | buffer | buffer |

c/cert/test/rules/ARR30-C/test.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ void test_valid_check_by_type(unsigned int index) {
3232
if (index < ARRAY_SIZE) {
3333
arr + index; // COMPLIANT - `index` cannot be be negative
3434
}
35+
}
36+
37+
void test_local_buffer_invalid_check(int index) {
38+
char buffer[ARRAY_SIZE];
39+
40+
if (index < ARRAY_SIZE) {
41+
char *ptr = buffer + index; // NON_COMPLIANT - `index` could be negative
42+
}
43+
44+
if (index >= 0 && index < ARRAY_SIZE + 2) {
45+
char *ptr = buffer + index; // NON_COMPLIANT - `index` could be too large
46+
}
47+
48+
if (index >= 0 && index < ARRAY_SIZE) {
49+
char *ptr = buffer + index; // COMPLIANT
50+
}
3551
}

0 commit comments

Comments
 (0)