...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string>
extern std::size_t get_index();
void f() {
std::string s("01234567");
s[get_index()] = '1';
} |
Compliant Solution (try
/catch
)
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdexcept> #include <string> extern std::size_t get_index(); void f() { std::string s("01234567"); try { s.at(get_index()) = '1'; } catch (std::out_of_range &) { // Handle error } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string> #include <locale> void capitalize(std::string &Ss) { std::locale Ll; Ss.front() = std::use_facet<std::ctype<char>>(Ll).toupper(Ss.front()); } |
Compliant Solution
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string> #include <locale> void capitalize(std::string &Ss) { if (Ss.empty()) { return; } std::locale Ll; Ss.front() = std::use_facet<std::ctype<char>>(Ll).toupper(Ss.front()); } |
Risk Assessment
...