Skip to content

Commit a12f9f5

Browse files
committed
sonarqubecloud error corrected
1 parent db6d1de commit a12f9f5

File tree

11 files changed

+32
-26
lines changed

11 files changed

+32
-26
lines changed

src/request_body_processor/json.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ JsonSinkStatus endContainer(std::deque<JSONContainer *> *containers,
5757
delete container;
5858

5959
if (containers->empty() == false) {
60-
JSONContainerArray *array = dynamic_cast<JSONContainerArray *>(
61-
containers->back());
60+
auto *array = dynamic_cast<JSONContainerArray *>(containers->back());
6261
if (array != nullptr) {
6362
array->m_elementCounter++;
6463
}

src/request_body_processor/json_adapter.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ JsonParseResult normalizeResult(JsonParseResult result) {
5656
} // namespace
5757

5858
JsonParseResult JSONAdapter::parse(std::string &input,
59-
JsonEventSink *sink, const JsonBackendParseOptions &options) const {
59+
JsonEventSink *sink,
60+
const JsonBackendParseOptions &options [[maybe_unused]]) const {
6061
if (sink == nullptr) {
6162
return makeResult(JsonParseStatus::InternalError,
6263
JsonSinkStatus::InternalError, "JSON event sink is null.");
@@ -78,7 +79,8 @@ JsonParseResult JSONAdapter::parse(std::string &input,
7879
}
7980

8081
JsonParseResult JSONAdapter::parse(const std::string &input,
81-
JsonEventSink *sink, const JsonBackendParseOptions &options) const {
82+
JsonEventSink *sink,
83+
const JsonBackendParseOptions &options [[maybe_unused]]) const {
8284
if (sink == nullptr) {
8385
return makeResult(JsonParseStatus::InternalError,
8486
JsonSinkStatus::InternalError, "JSON event sink is null.");

src/request_body_processor/json_adapter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ namespace modsecurity::RequestBodyProcessor {
2525
class JSONAdapter {
2626
public:
2727
JsonParseResult parse(std::string &input, JsonEventSink *sink,
28-
const JsonBackendParseOptions &options = JsonBackendParseOptions()) const;
28+
const JsonBackendParseOptions &options [[maybe_unused]]
29+
= JsonBackendParseOptions()) const;
2930

3031
JsonParseResult parse(const std::string &input, JsonEventSink *sink,
31-
const JsonBackendParseOptions &options = JsonBackendParseOptions()) const;
32+
const JsonBackendParseOptions &options [[maybe_unused]]
33+
= JsonBackendParseOptions()) const;
3234
};
3335

3436
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json_backend_jsoncons.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ class RawJsonTokenCursor {
372372

373373
(*offset)++;
374374
while (*offset < m_input.size()) {
375-
char current = m_input[(*offset)++];
375+
char current = m_input[*offset];
376+
(*offset)++;
376377
if (current == '\\') {
377378
if (*offset >= m_input.size()) {
378379
if (detail != nullptr) {
@@ -381,7 +382,9 @@ class RawJsonTokenCursor {
381382
return false;
382383
}
383384

384-
if (char escaped = m_input[(*offset)++]; escaped == 'u') {
385+
char escaped = m_input[*offset];
386+
(*offset)++;
387+
if (escaped == 'u') {
385388
for (int i = 0; i < 4; i++) {
386389
if (*offset >= m_input.size()
387390
|| !isHexDigit(m_input[*offset])) {

src/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ std::string Transaction::toJSON(int parts) {
16011601
m_variableRequestHeaders.resolve(&l);
16021602
for (auto &h : l) {
16031603
std::string header_name =
1604-
utils::string::toHexIfNeeded(h->getKey().c_str());
1604+
utils::string::toHexIfNeeded(h->getKey());
16051605
std::string header_value =
16061606
utils::string::toHexIfNeeded(h->getValue());
16071607
addString(header_name, header_value);

src/utils/json_writer.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
namespace modsecurity::utils {
2222

2323
JsonWriter::JsonWriter(bool pretty, std::string indent)
24-
: m_output(),
25-
m_stack(),
26-
m_pretty(pretty),
24+
: m_pretty(pretty),
2725
m_indent(std::move(indent)) { }
2826

2927
void JsonWriter::start_object() {

test/benchmark/json_benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct Metrics {
6666
unsigned long long parse_error_count{0};
6767
};
6868

69-
const char *usage_message =
69+
const char *const usage_message =
7070
"Usage: json_benchmark --scenario NAME [--iterations N] "
7171
"[--target-bytes N] [--depth N] [--include-invalid] [--output json]";
7272

@@ -322,7 +322,7 @@ Metrics runBenchmark(modsecurity::ModSecurity *modsec,
322322
"ModSecurity-json-benchmark/1.0");
323323
transaction.addRequestHeader("Content-Type", "application/json");
324324
const std::string content_length = std::to_string(body.size());
325-
transaction.addRequestHeader("Content-Length", content_length.c_str());
325+
transaction.addRequestHeader("Content-Length", content_length);
326326
transaction.processRequestHeaders();
327327

328328
const auto append_start = Clock::now();

test/benchmark/run-json-benchmarks.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ usage() {
66
cat <<'EOF'
77
Usage: test/benchmark/run-json-benchmarks.sh --simdjson-build DIR --jsoncons-build DIR [--include-invalid]
88
EOF
9+
return
910
}
1011

1112
simdjson_build=""

test/regression/regression_test.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::vector<std::pair<std::string, std::string>> json_object_to_map(
7676
std::string_view key;
7777
modsecurity_test::json::JsonValue child;
7878

79-
if (modsecurity_test::json::get(std::move(field_result), &field)
79+
if (modsecurity_test::json::get(field_result, &field)
8080
== false) {
8181
continue;
8282
}
@@ -216,7 +216,7 @@ std::unique_ptr<RegressionTest> RegressionTest::from_json_value(
216216
std::string_view key;
217217
modsecurity_test::json::JsonValue child;
218218

219-
if (modsecurity_test::json::get(std::move(field_result), &field)
219+
if (modsecurity_test::json::get(field_result, &field)
220220
== false) {
221221
continue;
222222
}
@@ -265,7 +265,7 @@ void RegressionTest::update_client_from_json_value(
265265
std::string_view key;
266266
modsecurity_test::json::JsonValue child;
267267

268-
if (modsecurity_test::json::get(std::move(field_result), &field)
268+
if (modsecurity_test::json::get(field_result, &field)
269269
== false) {
270270
continue;
271271
}
@@ -292,7 +292,7 @@ void RegressionTest::update_server_from_json_value(
292292
std::string_view key;
293293
modsecurity_test::json::JsonValue child;
294294

295-
if (modsecurity_test::json::get(std::move(field_result), &field)
295+
if (modsecurity_test::json::get(field_result, &field)
296296
== false) {
297297
continue;
298298
}
@@ -320,7 +320,7 @@ void RegressionTest::update_request_from_json_value(
320320
std::string_view key;
321321
modsecurity_test::json::JsonValue child;
322322

323-
if (modsecurity_test::json::get(std::move(field_result), &field)
323+
if (modsecurity_test::json::get(field_result, &field)
324324
== false) {
325325
continue;
326326
}
@@ -355,7 +355,7 @@ void RegressionTest::update_response_from_json_value(
355355
std::string_view key;
356356
modsecurity_test::json::JsonValue child;
357357

358-
if (modsecurity_test::json::get(std::move(field_result), &field)
358+
if (modsecurity_test::json::get(field_result, &field)
359359
== false) {
360360
continue;
361361
}
@@ -387,7 +387,7 @@ void RegressionTest::update_expected_from_json_value(
387387
std::string_view key;
388388
modsecurity_test::json::JsonValue child;
389389

390-
if (modsecurity_test::json::get(std::move(field_result), &field)
390+
if (modsecurity_test::json::get(field_result, &field)
391391
== false) {
392392
continue;
393393
}
@@ -493,14 +493,13 @@ std::unique_ptr<RegressionTests> RegressionTests::from_json_value(
493493
== false) {
494494
continue;
495495
}
496-
tests->tests.emplace_back(
497-
std::move(RegressionTest::from_json_value(test_value)));
496+
tests->tests.emplace_back(RegressionTest::from_json_value(test_value));
498497
}
499498
return tests;
500499
}
501500

502501
if (type == modsecurity_test::json::JsonType::Object) {
503-
tests->tests.emplace_back(std::move(RegressionTest::from_json_value(value)));
502+
tests->tests.emplace_back(RegressionTest::from_json_value(value));
504503
}
505504

506505
return tests;
@@ -520,7 +519,7 @@ std::string RegressionTests::toJSON() const {
520519
writer.key(key);
521520
writer.string(value);
522521
};
523-
const auto addStringIfNonEmpty = [&writer, &addString](
522+
const auto addStringIfNonEmpty = [&addString](
524523
std::string_view key, const std::string &value) {
525524
if (value.empty() == false) {
526525
addString(key, value);

test/run-json-backend-matrix.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Exit codes:
1414
13 backend result difference
1515
64 invalid usage
1616
EOF
17+
return
1718
}
1819

1920
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -76,6 +77,7 @@ extract_summary() {
7677
print backend "\t" m[2] "\t" m[3] "\t" m[1];
7778
}
7879
' "${input_log}" > "${output_tsv}"
80+
return
7981
}
8082

8183
run_backend() {

0 commit comments

Comments
 (0)