The index operators
Code Block |
---|
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
string bs("01234567");
size_t i = f();
bs[i] = '\0';
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
string bs("01234567");
try {
size_t i = f();
bs.at(i) = '\0';
}
catch (...) {
cerr << "Index out of range" << endl;
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
string bs("01234567");
for (int i=0; i < 100; i++) {
bs[i] = '\0';
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
size_t const max_fill = 100;
std::string bs("01234567");
fill(bs.begin(), bs.begin()+std::min(max_fill, bs.length()), '\0' );
|
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
STR39-CPP | high | likely | high | P9 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
| -wc "::std::vector::[]" |
Bibliography
[Seacord 05] Chapter 2 Strings
[ISO/IEC 14882-2003] Section 21.3.4 basic_string element access
...