Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Coding style conformance

...

Code Block
bgColor#FFcccc
langcpp
#include <string>
 
extern std::size_t get_index();
 
void f() {
  std::string s("01234567");
  s[get_index()] = '1';

}

Compliant Solution (try/catch)

...

Code Block
bgColor#ccccff
langcpp
#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
bgColor#FFcccc
langcpp
#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
bgColor#ccccff
langcpp
#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

...