This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ce7287b906 cppcheck - records. Fix few warnings, nothing major.
(#12066)
ce7287b906 is described below
commit ce7287b906b07fdfebdce13b91a92b4e13fa7d59
Author: Damian Meden <[email protected]>
AuthorDate: Mon Mar 24 20:08:28 2025 +0100
cppcheck - records. Fix few warnings, nothing major. (#12066)
* cppcheck - records, Fix few warnings, nothing major.
---
include/records/RecYAMLDefs.h | 4 +-
src/records/RecYAMLDecoder.cc | 76 ++++++++++++++++++------------------
src/traffic_ctl/FileConfigCommand.cc | 3 +-
3 files changed, 42 insertions(+), 41 deletions(-)
diff --git a/include/records/RecYAMLDefs.h b/include/records/RecYAMLDefs.h
index 5f840afa33..4238dbef31 100644
--- a/include/records/RecYAMLDefs.h
+++ b/include/records/RecYAMLDefs.h
@@ -73,7 +73,7 @@ struct CfgNode {
/// @brief Append field name in order to build up the record name.
void
- append_field_name() const
+ append_field_name()
{
if (!_legacy.record_name.empty()) {
_legacy.record_name.append(".");
@@ -92,5 +92,5 @@ private:
struct Legacy {
std::string record_name;
};
- mutable Legacy _legacy;
+ Legacy _legacy;
};
diff --git a/src/records/RecYAMLDecoder.cc b/src/records/RecYAMLDecoder.cc
index f0e9d6293e..2b54d4e191 100644
--- a/src/records/RecYAMLDecoder.cc
+++ b/src/records/RecYAMLDecoder.cc
@@ -46,7 +46,7 @@ const inline std::string RECORD_YAML_ROOT_STR{"records"};
namespace detail
{
-void flatten_node(CfgNode const &field,
RecYAMLNodeHandler handler, swoc::Errata &errata);
+
std::pair<RecDataT, std::string> try_deduce_type(YAML::Node const &node);
// Helper class to make the code less verbose when lock is needed.
@@ -65,6 +65,43 @@ struct scoped_cond_lock {
}
bool _lock{false};
};
+
+/// @brief Iterate over a node and build up the field name from it.
+///
+/// This function walks down a YAML node till it find a scalar type while
building the record name, so if a node is something like
+/// this:
+///
+/// diags:
+/// debug:
+/// enabled: 0
+///
+/// this function will build up the record name "diags.debug.enabled" and
then it prepend the "proxy.config" to each name, this
+/// will be the record name already known by ATS. Every time a scalar node is
completed then the handler function will be called.
+///
+/// @param field Parent node.
+/// @param handler Scalar node function handler, called every time a scalar
type is found.
+/// @param errata Holds the errors detected.
+template <typename T>
+void
+flatten_node(T &&field, RecYAMLNodeHandler handler, swoc::Errata &errata)
+
+{
+ switch (field.value_node.Type()) {
+ case YAML::NodeType::Map: {
+ field.append_field_name();
+ for (auto &&it : field.value_node) {
+ flatten_node(T{it.first, it.second, field.get_record_name()}, handler,
errata);
+ }
+ } break;
+ case YAML::NodeType::Sequence:
+ case YAML::NodeType::Scalar:
+ case YAML::NodeType::Null: {
+ field.append_field_name();
+ handler(field, errata);
+ } break;
+ default:; // done
+ }
+}
} // namespace detail
void
@@ -151,7 +188,7 @@ ParseRecordsFromYAML(YAML::Node root, RecYAMLNodeHandler
handler, bool lock /*fa
if (auto ts = root[RECORD_YAML_ROOT_STR]; ts.size()) {
for (auto &&n : ts) {
- detail::flatten_node({n.first, n.second, CONFIG_RECORD_PREFIX}, handler,
errata);
+ detail::flatten_node(CfgNode{n.first, n.second, CONFIG_RECORD_PREFIX},
handler, errata);
}
} else {
return swoc::Errata(ERRATA_ERROR, "'{}' root key not present or no fields
to read. Default values will be used",
@@ -184,41 +221,6 @@ try_deduce_type(YAML::Node const &node)
std::string text;
return {RecDataT::RECD_NULL, swoc::bwprint(text, "Unknown tag type '{}'",
tag)};
}
-
-/// @brief Iterate over a node and build up the field name from it.
-///
-/// This function walks down a YAML node till it find a scalar type while
building the record name, so if a node is something like
-/// this:
-///
-/// diags:
-/// debug:
-/// enabled: 0
-///
-/// this function will build up the record name "diags.debug.enabled" and
then it prepend the "proxy.config" to each name, this
-/// will be the record name already known by ATS. Every time a scalar node is
completed then the handler function will be called.
-///
-/// @param field Parent node.
-/// @param handler Scalar node function handler, called every time a scalar
type is found.
-/// @param errata Holds the errors detected.
-void
-flatten_node(CfgNode const &field, RecYAMLNodeHandler handler, swoc::Errata
&errata)
-{
- switch (field.value_node.Type()) {
- case YAML::NodeType::Map: {
- field.append_field_name();
- for (auto &it : field.value_node) {
- flatten_node({it.first, it.second, field.get_record_name()}, handler,
errata);
- }
- } break;
- case YAML::NodeType::Sequence:
- case YAML::NodeType::Scalar:
- case YAML::NodeType::Null: {
- field.append_field_name();
- handler(field, errata);
- } break;
- default:; // done
- }
-}
} // namespace detail
namespace swoc
diff --git a/src/traffic_ctl/FileConfigCommand.cc
b/src/traffic_ctl/FileConfigCommand.cc
index b52f9775b3..1d6c8d9f75 100644
--- a/src/traffic_ctl/FileConfigCommand.cc
+++ b/src/traffic_ctl/FileConfigCommand.cc
@@ -234,8 +234,7 @@ FileConfigCommand::config_get()
FlatYAMLAccessor::load(YAML::LoadAllFromFile(filename));
for (auto const &var : data) { // we support multiple get's
- std::string variable = amend_variable_name(var);
- auto [found, search] = find_node(variable);
+ auto [found, search] = find_node(amend_variable_name(var));
if (found) {
_printer->write_output(swoc::bwprint(text, "{}: {}", var,
search.as<std::string>()));