Skip to content

Commit 9fd64a2

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Sonar fixes
1 parent ac9e313 commit 9fd64a2

File tree

4 files changed

+108
-90
lines changed

4 files changed

+108
-90
lines changed

applications/zpc/components/zcl_cluster_servers/src/user_credential_cluster_server.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,13 @@ std::string get_payload_value(attribute_store::attribute updated_node_cpp,
903903
// Credential data are encoded in different way that's why we store them as raw byte array and interpret their value
904904

905905
std::string output;
906-
auto data = updated_node_cpp.reported<std::vector<uint8_t>>();
906+
auto raw_data = updated_node_cpp.reported<std::vector<uint8_t>>();
907907

908908
// Check if we need to convert the value to UTF-8
909909
if (need_utf8_conversion) {
910910
std::u16string utf16_str;
911-
for (size_t i = 0; i < data.size(); i += 2) {
912-
char16_t char16 = (data[i] << 8) | data[i + 1];
911+
for (size_t i = 0; i < raw_data.size(); i += 2) {
912+
char16_t char16 = (raw_data[i] << 8) | raw_data[i + 1];
913913
utf16_str.push_back(char16);
914914
}
915915
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> cnv;
@@ -918,8 +918,8 @@ std::string get_payload_value(attribute_store::attribute updated_node_cpp,
918918
sl_log_error(LOG_TAG, "Error converting UTF-16 to UTF-8");
919919
}
920920
} else {
921-
output.reserve(data.size());
922-
for (auto c: data) {
921+
output.reserve(raw_data.size());
922+
for (auto c: raw_data) {
923923
output.push_back(static_cast<char>(c));
924924
}
925925
}
@@ -1005,7 +1005,7 @@ void publish_mqtt_topic(const std::string &base_topic,
10051005
void on_attribute_update(
10061006
attribute_store_node_t updated_node,
10071007
attribute_store_change_t change,
1008-
std::function<std::string(attribute_store::attribute)> get_base_mqtt_topic,
1008+
const std::function<std::string(attribute_store::attribute)>& get_base_mqtt_topic,
10091009
const user_attributes_mqtt_map_t &attributes)
10101010
{
10111011
try {
@@ -1087,7 +1087,7 @@ void on_uuic_slot_update(
10871087
old_credential_slot.credential_type);
10881088
// Simulate deletion of the old slot
10891089
// First simulate deletion of all attributes
1090-
for (auto [attribute_store_type, mqtt_data]: credential_attributes) {
1090+
for (const auto& [attribute_store_type, mqtt_data]: credential_attributes) {
10911091
std::string mqtt_topic
10921092
= mqtt_topic_add_attribute(old_credential_topic, mqtt_data.topic);
10931093
uic_mqtt_publish(mqtt_topic.c_str(), "", 0, true);
@@ -1102,7 +1102,7 @@ void on_uuic_slot_update(
11021102
}
11031103

11041104
void on_user_credential_message(sl_log_level_t log_level,
1105-
const std::string message)
1105+
const std::string& message)
11061106
{
11071107
nlohmann::json payload;
11081108
payload["level"] = log_level;

applications/zpc/components/zwave_command_classes/src/private/user_credential/user_credential_helpers.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,16 @@ bool is_credential_available(attribute_store_node_t endpoint_node,
181181

182182
for_each_credential_type_nodes(
183183
endpoint_node,
184-
[&](attribute_store::attribute &credential_type_node) {
185-
for (auto &credential_slot_node:
186-
credential_type_node.children(ATTRIBUTE(CREDENTIAL_SLOT))) {
184+
[&credential_available, &credential_slot](
185+
attribute_store::attribute &current_credential_type_node) {
186+
for (auto &current_credential_slot_node:
187+
current_credential_type_node.children(ATTRIBUTE(CREDENTIAL_SLOT))) {
187188
// If this credential slot node doesn't have a reported value, check the next one
188-
if (!credential_slot_node.reported_exists()) {
189+
if (!current_credential_slot_node.reported_exists()) {
189190
continue;
190191
}
191192

192-
if (credential_slot_node.reported<user_credential_slot_t>()
193+
if (current_credential_slot_node.reported<user_credential_slot_t>()
193194
== credential_slot) {
194195
credential_available = false;
195196
return;

0 commit comments

Comments
 (0)