Skip to content

Commit d05a1ae

Browse files
kkasperczyk-noArekBalysNordic
authored andcommitted
samples: matter: Fixed issues found by static code analysis
Fixed several issues found by the coverity during static code analysis. Signed-off-by: Kamil Kasperczyk <[email protected]>
1 parent 4b87c45 commit d05a1ae

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

samples/matter/common/src/event_triggers/default_event_triggers.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ CHIP_ERROR RebootCallback(TestEventTrigger::TriggerValue delayMs)
119119
sys_reboot(SYS_REBOOT_WARM);
120120
},
121121
nullptr /* context */);
122-
123-
return CHIP_NO_ERROR;
124122
}
125123

126124
#ifdef CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_EVENT_TRIGGERS
@@ -152,7 +150,7 @@ CHIP_ERROR BlockMatterThreadCallback(TestEventTrigger::TriggerValue blockingTime
152150

153151
LOG_INF("Blocking Matter thread for %d seconds", blockingTimeS);
154152

155-
while (startTime + (blockingTimeS * 1000) > k_uptime_get()) {
153+
while (startTime + static_cast<int64_t>(blockingTimeS) * 1000 > k_uptime_get()) {
156154
;
157155
}
158156

samples/matter/common/src/event_triggers/event_triggers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CHIP_ERROR TestEventTrigger::RegisterTestEventTriggerHandler(chip::TestEventTrig
3737
{
3838
VerifyOrReturnError(triggerDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
3939

40-
for (size_t idx = 0; idx < kMaxEventTriggers; idx++) {
40+
for (size_t idx = 0; idx < kMaxEventTriggersHandlers; idx++) {
4141
if (mHandlers[idx] == nullptr) {
4242
mHandlers[idx] = triggerDelegate;
4343
return CHIP_NO_ERROR;

samples/matter/common/src/event_triggers/event_triggers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class TestEventTrigger : public chip::TestEventTriggerDelegate {
3232
/* Define the maximum available event triggers that can be registered. */
3333
constexpr static TriggerSlot kMaxEventTriggers = CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS_MAX;
3434
constexpr static TriggerSlot kInvalidTriggerSlot = CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS_MAX + 1;
35-
constexpr static TriggerSlot kMaxEventTriggersHandlers = CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS_MAX_TRIGGERS_DELEGATES;
35+
constexpr static TriggerSlot kMaxEventTriggersHandlers =
36+
CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS_MAX_TRIGGERS_DELEGATES;
3637
constexpr static uint8_t kDisableEventTriggersKey[chip::TestEventTriggerDelegate::kEnableKeyLength] = {
3738
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3839
};
@@ -128,6 +129,6 @@ class TestEventTrigger : public chip::TestEventTriggerDelegate {
128129
uint8_t mEnableKeyData[chip::TestEventTriggerDelegate::kEnableKeyLength] = {};
129130
chip::MutableByteSpan mEnableKey{ mEnableKeyData };
130131
Nrf::FiniteMap<EventTriggerId, EventTrigger, kMaxEventTriggers> mTriggersMap;
131-
chip::TestEventTriggerHandler* mHandlers[kMaxEventTriggersHandlers];
132+
chip::TestEventTriggerHandler *mHandlers[kMaxEventTriggersHandlers] = {};
132133
};
133134
}; // namespace Nrf::Matter

samples/matter/thermostat/src/app_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CHIP_ERROR AppTask::Init()
7272
}
7373
err = TemperatureManager::Instance().Init();
7474
if (err != CHIP_NO_ERROR) {
75-
LOG_ERR("TempMgr Init fail");
75+
LOG_ERR("TemperatureManager Init fail");
7676
}
7777
return err;
7878
} }));

samples/matter/thermostat/src/temperature_manager.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
1313
using namespace chip;
1414
using namespace ::chip::DeviceLayer;
1515
using namespace ::chip::app::Clusters;
16+
using namespace chip::app::Clusters::Thermostat::Attributes;
17+
using namespace Protocols::InteractionModel;
1618

1719
constexpr EndpointId kThermostatEndpoint = 1;
1820

@@ -38,15 +40,20 @@ uint8_t ReturnRemainderValue(int16_t Value)
3840

3941
CHIP_ERROR TemperatureManager::Init()
4042
{
43+
CHIP_ERROR err = CHIP_NO_ERROR;
44+
4145
PlatformMgr().LockChipStack();
42-
Thermostat::Attributes::LocalTemperature::Get(kThermostatEndpoint, mLocalTempCelsius);
43-
Thermostat::Attributes::OutdoorTemperature::Get(kThermostatEndpoint, mOutdoorTempCelsius);
44-
Thermostat::Attributes::OccupiedCoolingSetpoint::Get(kThermostatEndpoint, &mCoolingCelsiusSetPoint);
45-
Thermostat::Attributes::OccupiedHeatingSetpoint::Get(kThermostatEndpoint, &mHeatingCelsiusSetPoint);
46-
Thermostat::Attributes::SystemMode::Get(kThermostatEndpoint, &mThermMode);
46+
47+
VerifyOrExit(Status::Success == LocalTemperature::Get(kThermostatEndpoint, mLocalTempCelsius), err = CHIP_IM_GLOBAL_STATUS(Failure));
48+
VerifyOrExit(Status::Success == OutdoorTemperature::Get(kThermostatEndpoint, mOutdoorTempCelsius), err = CHIP_IM_GLOBAL_STATUS(Failure));
49+
VerifyOrExit(Status::Success == OccupiedCoolingSetpoint::Get(kThermostatEndpoint, &mCoolingCelsiusSetPoint), err = CHIP_IM_GLOBAL_STATUS(Failure));
50+
VerifyOrExit(Status::Success == OccupiedHeatingSetpoint::Get(kThermostatEndpoint, &mHeatingCelsiusSetPoint), err = CHIP_IM_GLOBAL_STATUS(Failure));
51+
VerifyOrExit(Status::Success == SystemMode::Get(kThermostatEndpoint, &mThermMode), err = CHIP_IM_GLOBAL_STATUS(Failure));
52+
53+
exit:
4754
PlatformMgr().UnlockChipStack();
4855

49-
return CHIP_NO_ERROR;
56+
return err;
5057
}
5158

5259
void TemperatureManager::LogThermostatStatus()
@@ -76,31 +83,35 @@ void TemperatureManager::LogThermostatStatus()
7683
void TemperatureManager::AttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t *value,
7784
uint16_t size)
7885
{
86+
Status status;
87+
7988
switch (attributeId) {
80-
case Thermostat::Attributes::LocalTemperature::Id: {
81-
Thermostat::Attributes::LocalTemperature::Get(kThermostatEndpoint, mLocalTempCelsius);
89+
case LocalTemperature::Id: {
90+
status = LocalTemperature::Get(kThermostatEndpoint, mLocalTempCelsius);
91+
VerifyOrReturn(Status::Success == status, LOG_ERR("Failed to get Thermostat LocalTemperature attribute"));
8292
} break;
8393

84-
case Thermostat::Attributes::OutdoorTemperature::Id: {
85-
Thermostat::Attributes::OutdoorTemperature::Get(kThermostatEndpoint, mOutdoorTempCelsius);
94+
case OutdoorTemperature::Id: {
95+
status = OutdoorTemperature::Get(kThermostatEndpoint, mOutdoorTempCelsius);
96+
VerifyOrReturn(Status::Success == status, LOG_ERR("Failed to get Thermostat OutdoorTemperature attribute"));
8697
} break;
8798

88-
case Thermostat::Attributes::OccupiedCoolingSetpoint::Id: {
99+
case OccupiedCoolingSetpoint::Id: {
89100
mCoolingCelsiusSetPoint = *reinterpret_cast<int16_t *>(value);
90101
LOG_INF("Cooling TEMP: %d", mCoolingCelsiusSetPoint);
91102
} break;
92103

93-
case Thermostat::Attributes::OccupiedHeatingSetpoint::Id: {
104+
case OccupiedHeatingSetpoint::Id: {
94105
mHeatingCelsiusSetPoint = *reinterpret_cast<int16_t *>(value);
95106
LOG_INF("Heating TEMP %d", mHeatingCelsiusSetPoint);
96107
} break;
97108

98-
case Thermostat::Attributes::SystemMode::Id: {
109+
case SystemMode::Id: {
99110
mThermMode = static_cast<app::Clusters::Thermostat::SystemModeEnum>(*value);
100111
} break;
101112

102113
default: {
103-
LOG_INF("Unhandled thermostat attribute %x", attributeId);
114+
LOG_ERR("Unhandled thermostat attribute %x", attributeId);
104115
return;
105116
} break;
106117
}

samples/matter/thermostat/src/temperature_measurement/sensor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ constexpr int16_t sMockTemp[] = { 2000, 2731, 1600, 2100, 1937, 3011, 1500, 1899
3737

3838
TemperatureSensor::TemperatureSensor()
3939
{
40+
mCycleCounter = 0;
4041
mMockTempIndex = 0;
4142
mPreviousTemperature = startingMockedValue;
4243
BindingHandler::Init();

0 commit comments

Comments
 (0)