-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
43 lines (36 loc) · 872 Bytes
/
test.cpp
File metadata and controls
43 lines (36 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <string>
int get_index();
void test_string() {
std::string s("adsvsdfdsf");
s[get_index()] = '1'; // NON_COMPLIANT
s[0]; // COMPLIANT
s[9]; // COMPLIANT
s[10]; // NON_COMPLIANT
s[11]; // NON_COMPLIANT
}
void test_range_check(std::string &s) {
if (s.size() > 2) {
s[0]; // COMPLIANT
s[1]; // COMPLIANT
s[2]; // COMPLIANT
s[3]; // NON_COMPLIANT
} else {
s[0]; // NON_COMPLIANT
s[1]; // NON_COMPLIANT
s[2]; // NON_COMPLIANT
s[3]; // NON_COMPLIANT
}
}
void test_different_constructors(char *buffer) {
std::string s;
s[0]; // NON_COMPLIANT - s is empty
// Creates a string of exactly size 2 based on buffer
std::string s2(buffer, 2);
s2[0]; // COMPLIANT
s2[1]; // COMPLIANT
s2[2]; // NON_COMPLIANT
std::string s3(2, ' ');
s3[0]; // COMPLIANT
s3[1]; // COMPLIANT
s3[2]; // NON_COMPLIANT
}