forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
66 lines (58 loc) · 1.5 KB
/
test.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <algorithm>
#include <vector>
void f1(std::vector<int> &v) {
{
auto i = v.begin();
++i; // NON_COMPLIANT
i = i++; // NON_COMPLIANT
i = i + 10; // NON_COMPLIANT
}
{
auto i = v.begin();
if (v.size() > 10) {
++i; // COMPLIANT
i = i++; // COMPLIANT
i = i + 10; // COMPLIANT
}
}
for (auto i = v.begin(),
l = (i + std::min(static_cast<std::vector<int>::size_type>(10),
v.size())); // NON_COMPLIANT - technically in the
// calculation
i != l; ++i) { // COMPLIANT
}
for (auto i = v.begin();; ++i) { // NON_COMPLIANT
}
}
void test_fp_reported_in_374(std::vector<int> &v) {
{
auto end = v.end();
for (auto i = v.begin(); i != end; ++i) { // COMPLIANT
}
}
{
auto end2 = v.end();
end2++; // NON_COMPLIANT
for (auto i = v.begin(); i != end2;
++i) { // NON_COMPLIANT[FALSE_NEGATIVE] - case of invalidations to
// check before use expected to be less frequent, can model in
// future if need be
}
}
}
void test(std::vector<int> &v, std::vector<int> &v2) {
{
auto end = v2.end();
for (auto i = v.begin(); i != end; ++i) { // NON_COMPLIANT - wrong check
}
}
}
void test2(std::vector<int> &v) {
auto i = v.begin();
while (1) {
auto i2 = ((i != v.end()) != 0);
if (!i2)
break;
(void)((++i)); // COMPLIANT[FALSE_POSITIVE]
}
}