...
Code Block |
---|
|
#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 |
---|
|
#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_string
exampleString
's internal buffer is not generated until after the modifications from replace()
have completed:
Code Block |
---|
|
#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
...