Skip to content

Commit 7c4f24a

Browse files
Merge pull request #74 from Easton97-Jens/codex/systematische-behebung-offener-sonar-probleme-7954xf
Modernize codebase: nullptr/default initializers, std::string_view, smart pointers and minor cleanups
2 parents 3ec86cf + 57bf6d2 commit 7c4f24a

29 files changed

Lines changed: 157 additions & 151 deletions

headers/modsecurity/audit_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <iostream>
1818
#include <fstream>
1919
#include <string>
20+
#include <string_view>
2021
#endif
2122

2223
#ifndef HEADERS_MODSECURITY_AUDIT_LOG_H_

headers/modsecurity/rules_set_phases.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifdef __cplusplus
2121
#include <ctime>
2222
#include <iostream>
23+
#include <memory>
2324
#include <string>
2425
#include <vector>
2526
#include <list>
@@ -60,4 +61,4 @@ class RulesSetPhases {
6061
} // namespace modsecurity
6162
#endif
6263

63-
#endif // HEADERS_MODSECURITY_RULES_SET_PHASES_H_
64+
#endif // HEADERS_MODSECURITY_RULES_SET_PHASES_H_

headers/modsecurity/rules_set_properties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifdef __cplusplus
2626
#include <ctime>
2727
#include <iostream>
28+
#include <memory>
2829
#include <string>
2930
#include <vector>
3031
#include <list>

src/actions/ctl/rule_remove_by_id.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*
1414
*/
1515

16+
#include <list>
1617
#include <string>
18+
#include <utility>
1719

1820
#include "modsecurity/actions/action.h"
1921
#include "modsecurity/transaction.h"

src/anchored_set_variable.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <ctime>
1717
#include <iostream>
1818
#include <fstream>
19+
#include <memory>
1920
#include <string>
2021
#include <vector>
2122

src/anchored_variable.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <ctime>
1717
#include <iostream>
1818
#include <fstream>
19+
#include <memory>
1920
#include <string>
2021
#include <vector>
2122

src/audit_log/audit_log.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ctype.h>
2121

2222
#include <fstream>
23+
#include <string_view>
2324

2425
#include "modsecurity/transaction.h"
2526
#include "modsecurity/rule_message.h"

src/operators/pm_from_file.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "src/operators/pm_from_file.h"
1717

18+
#include <memory>
1819
#include <string>
1920

2021
#include "src/operators/operator.h"

src/operators/validate_byte_range.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "src/operators/validate_byte_range.h"
1717

18+
#include <array>
1819
#include <cctype>
1920
#include <cstring>
2021
#include <string>

src/request_body_processor/json.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@
2020
#include "src/request_body_processor/json.h"
2121

2222
#include <chrono>
23+
#include <cstddef>
2324
#include <cstdint>
2425
#include <memory>
2526
#include <string>
2627

28+
#include "modsecurity/transaction.h"
2729
#include "src/request_body_processor/json_adapter.h"
2830
#include "src/request_body_processor/json_instrumentation.h"
2931

3032

3133
namespace modsecurity::RequestBodyProcessor {
3234

3335
static const double json_depth_limit_default = 10000.0;
34-
static const char* json_depth_limit_exceeded_msg = ". Parsing depth limit exceeded";
36+
static const char *const json_depth_limit_exceeded_msg =
37+
". Parsing depth limit exceeded";
3538

3639
namespace {
3740

@@ -119,11 +122,7 @@ JsonSinkStatus addStringViewAsSinkStatus(JSON *json, std::string_view value) {
119122
} // namespace
120123

121124
JSON::JSON(Transaction *transaction) : m_transaction(transaction),
122-
m_current_key(""),
123-
m_data(""),
124-
m_max_depth(json_depth_limit_default),
125-
m_current_depth(0),
126-
m_depth_limit_exceeded(false) {
125+
m_max_depth(json_depth_limit_default) {
127126
}
128127

129128

@@ -185,11 +184,11 @@ bool JSON::complete(std::string *err) {
185184

186185

187186
int JSON::addArgument(const std::string& value) {
188-
std::string data("");
187+
std::string data;
189188
std::string path;
190189

191-
for (size_t i = 0; i < m_containers.size(); i++) {
192-
const JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
190+
for (size_t i = 0; i < m_containers.size(); i++) {
191+
const auto *a = dynamic_cast<JSONContainerArray *>(
193192
m_containers[i].get());
194193
path = path + m_containers[i]->m_name;
195194
if (a != nullptr) {
@@ -199,8 +198,8 @@ int JSON::addArgument(const std::string& value) {
199198
}
200199
}
201200

202-
if (m_containers.size() > 0) {
203-
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
201+
if (!m_containers.empty()) {
202+
auto *a = dynamic_cast<JSONContainerArray *>(
204203
m_containers.back().get());
205204
if (a) {
206205
a->m_elementCounter++;

0 commit comments

Comments
 (0)