mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Simplified lifetime management of tests
- Addresses Sonarcloud issues: - Rewrite the code so that you no longer need this "delete". - Make the type of this variable a reference-to-const.
This commit is contained in:
@@ -72,18 +72,11 @@ bool ModSecurityTest<T>::load_test_json(const std::string &file) {
|
||||
for ( int i = 0; i < num_tests; i++ ) {
|
||||
yajl_val obj = node->u.array.values[i];
|
||||
|
||||
T *u = T::from_yajl_node(obj);
|
||||
auto u = std::unique_ptr<T>(T::from_yajl_node(obj));
|
||||
u->filename = file;
|
||||
|
||||
if (this->count(u->filename + ":" + u->name) == 0) {
|
||||
auto vec = new std::vector<T *>;
|
||||
vec->push_back(u);
|
||||
std::string filename(u->filename + ":" + u->name);
|
||||
this->insert({filename, vec});
|
||||
} else {
|
||||
auto vec = this->at(u->filename + ":" + u->name);
|
||||
vec->push_back(u);
|
||||
}
|
||||
const auto key = u->filename + ":" + u->name;
|
||||
(*this)[key].push_back(std::move(u));
|
||||
}
|
||||
|
||||
yajl_tree_free(node);
|
||||
|
Reference in New Issue
Block a user