Versions Compared

Key

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

...

Code Block
bgColor#ccccff
langcpp
#include <deque><algorithm>
#include <algorithm><deque>
#include <iterator>
 
void f(const double *items, std::size_t count) {
  std::deque<double> d;
  std::transform(items, items + count, std::inserter(d, d.begin()),
                 [](double d) { return d + 41.0; });
}

...

Code Block
bgColor#ffcccc
langcpp
#include <iostream>
#include <string>
 
extern void g(const char *);
 
void f(std::string &example_stringexampleString) {
  const char *data = example_stringexampleString.data();
  // ...
  example_stringexampleString.replace(0, 2, "bb");
  // ...
  g(data);

}

...

In this compliant solution, the pointer to example_stringexampleString's internal buffer is not generated until after the modifications from replace() have completed:

Code Block
bgColor#ccccff
langcpp
#include <iostream>
#include <string>

extern void g(const char *);

void f(std::string &example_stringexampleString) {
  // ...
  example_stringexampleString.replace(0, 2, "bb");
  // ...
  g(example_stringexampleString.data());
}

Risk Assessment

...