Skip to content

Commit da065fb

Browse files
authored
Fix Coverity 1646593-1646605 (#13048)
src/config/storage.cc: - CID 1646599: span.hash_seed = std::move(hash_seed) - CID 1646594: vol_span_map[...].push_back(std::move(path_tok)) - CID 1646604: return {std::move(result), std::move(errata)} in parse_legacy_storage_config - CID 1646603: return {std::move(result), std::move(errata)} in parse_legacy_volume_config - CID 1646598: vol.scheme = std::move(s) - CID 1646593: both returns in parse_content use std::move(result) - CID 1646601: print original string src/config/unit_tests/test_storage.cc: - CID 1646605: config.spans.push_back(std::move(span1)) - CID 1646600: config.volumes.push_back(std::move(vol1)) (YAML test) - CID 1646595: config.spans.push_back(std::move(span1)) - CID 1646602: config.volumes.push_back(std::move(vol1)) (JSON test) src/iocore/cache/unit_tests/test_ConfigVolumes.cc: - CID 1646596 & 1646597: Added REQUIRE(vN != nullptr) guards
1 parent efada79 commit da065fb

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/config/storage.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ parse_legacy_storage_config(std::string_view content)
255255
span.name = path_tok;
256256
span.path = path_tok;
257257
span.size = size;
258-
span.hash_seed = hash_seed;
258+
span.hash_seed = std::move(hash_seed);
259259
result.spans.push_back(std::move(span));
260260

261261
if (volume_num > 0) {
262-
vol_span_map[volume_num].push_back(path_tok);
262+
vol_span_map[volume_num].push_back(std::move(path_tok));
263263
}
264264
}
265265

@@ -276,7 +276,7 @@ parse_legacy_storage_config(std::string_view content)
276276
result.volumes.push_back(std::move(vol));
277277
}
278278

279-
return {result, std::move(errata)};
279+
return {std::move(result), std::move(errata)};
280280
}
281281

282282
/**
@@ -435,7 +435,7 @@ parse_legacy_volume_config(std::string_view content)
435435
result.volumes.push_back(std::move(vol));
436436
}
437437

438-
return {result, std::move(errata)};
438+
return {std::move(result), std::move(errata)};
439439
}
440440

441441
} // namespace
@@ -511,16 +511,16 @@ template <> struct convert<config::StorageVolumeEntry> {
511511
throw ParserException(node.Mark(), "missing 'id' argument in cache.volumes[]");
512512
}
513513
vol.id = node[KEY_ID].as<int>();
514-
if (vol.id < 1 || vol.id > MAX_VOLUME_IDX) {
515-
throw ParserException(node.Mark(), "volume id out of range [1, 255]: " + std::to_string(vol.id));
514+
if (vol.id < 1 || MAX_VOLUME_IDX < vol.id) {
515+
throw ParserException(node.Mark(), "volume id out of range [1, 255]: " + node[KEY_ID].as<std::string>());
516516
}
517517

518518
if (node[KEY_SCHEME]) {
519519
std::string s = node[KEY_SCHEME].as<std::string>();
520520
if (s != "http") {
521521
throw ParserException(node.Mark(), "unsupported scheme '" + s + "' in cache.volumes[]");
522522
}
523-
vol.scheme = s;
523+
vol.scheme = std::move(s);
524524
}
525525

526526
if (node[KEY_SIZE]) {
@@ -692,10 +692,10 @@ StorageParser::parse_content(std::string_view content)
692692
}
693693

694694
} catch (std::exception const &ex) {
695-
return {result, swoc::Errata(ERRATA_ERROR_SEV, "YAML parse error: {}", ex.what())};
695+
return {std::move(result), swoc::Errata(ERRATA_ERROR_SEV, "YAML parse error: {}", ex.what())};
696696
}
697697

698-
return {result, std::move(errata)};
698+
return {std::move(result), std::move(errata)};
699699
}
700700

701701
ConfigResult<StorageConfig>

src/config/unit_tests/test_storage.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,14 @@ TEST_CASE("StorageMarshaller produces valid YAML", "[storage][marshaller][yaml]"
786786
span1.name = "span-1";
787787
span1.path = "/var/cache/span1";
788788
span1.size = 10LL * 1024 * 1024 * 1024;
789-
config.spans.push_back(span1);
789+
config.spans.push_back(std::move(span1));
790790

791791
StorageVolumeEntry vol1;
792792
vol1.id = 1;
793793
vol1.scheme = "http";
794794
vol1.size.in_percent = true;
795795
vol1.size.percent = 100;
796-
config.volumes.push_back(vol1);
796+
config.volumes.push_back(std::move(vol1));
797797

798798
StorageMarshaller marshaller;
799799
std::string yaml = marshaller.to_yaml(config);
@@ -826,11 +826,11 @@ TEST_CASE("StorageMarshaller produces valid JSON", "[storage][marshaller][json]"
826826
StorageSpanEntry span1;
827827
span1.name = "span-1";
828828
span1.path = "/var/cache/span1";
829-
config.spans.push_back(span1);
829+
config.spans.push_back(std::move(span1));
830830

831831
StorageVolumeEntry vol1;
832832
vol1.id = 1;
833-
config.volumes.push_back(vol1);
833+
config.volumes.push_back(std::move(vol1));
834834

835835
StorageMarshaller marshaller;
836836
std::string json = marshaller.to_json(config);

src/iocore/cache/unit_tests/test_ConfigVolumes.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ TEST_CASE("ConfigVolumes::complement")
143143
// - id: 2
144144
// size: 34%
145145
ConfigVol *v1 = config.cp_queue.head;
146+
REQUIRE(v1 != nullptr);
146147
CHECK(v1->size.percent == 66);
147148

148149
ConfigVol *v2 = config.cp_queue.next(v1);
150+
REQUIRE(v2 != nullptr);
149151
CHECK(v2->size.percent == 34);
150152
}
151153

@@ -170,6 +172,7 @@ TEST_CASE("ConfigVolumes::complement")
170172
// size: 100%
171173
ConfigVol *v1 = config.cp_queue.head;
172174

175+
REQUIRE(v1 != nullptr);
173176
CHECK(v1->size.is_empty());
174177
REQUIRE(v1->spans.size() == 1);
175178
CHECK(v1->spans[0].size.in_percent);
@@ -247,16 +250,19 @@ TEST_CASE("ConfigVolumes::complement")
247250
// size: 70%
248251
ConfigVol *v1 = config.cp_queue.head;
249252

253+
REQUIRE(v1 != nullptr);
250254
CHECK(v1->size.is_empty());
251255
CHECK(v1->spans[0].size.percent == 10);
252256

253257
ConfigVol *v2 = config.cp_queue.next(v1);
254258

259+
REQUIRE(v2 != nullptr);
255260
CHECK(v2->size.is_empty());
256261
CHECK(v2->spans[0].size.percent == 20);
257262

258263
ConfigVol *v3 = config.cp_queue.next(v2);
259264

265+
REQUIRE(v3 != nullptr);
260266
CHECK(v3->size.is_empty());
261267
CHECK(v3->spans[0].size.percent == 70);
262268
}
@@ -307,6 +313,7 @@ TEST_CASE("ConfigVolumes::complement")
307313
// size: 17%
308314
ConfigVol *v1 = config.cp_queue.head;
309315

316+
REQUIRE(v1 != nullptr);
310317
CHECK(v1->size.is_empty());
311318
REQUIRE(v1->spans.size() == 2);
312319

@@ -348,13 +355,15 @@ TEST_CASE("ConfigVolumes::complement")
348355
// size: 100%
349356
ConfigVol *v1 = config.cp_queue.head;
350357

358+
REQUIRE(v1 != nullptr);
351359
CHECK(v1->size.is_empty());
352360
REQUIRE(v1->spans.size() == 1);
353361
CHECK(v1->spans[0].size.in_percent);
354362
CHECK(v1->spans[0].size.percent == 100);
355363

356364
ConfigVol *v2 = config.cp_queue.next(v1);
357365

366+
REQUIRE(v2 != nullptr);
358367
CHECK(v2->size.in_percent);
359368
CHECK(v2->size.percent == 100);
360369
}

0 commit comments

Comments
 (0)