From 9e886ccdeb69b2b636d7affd01026be91c447c80 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Thu, 8 Aug 2024 11:51:34 +0530 Subject: [PATCH] Address review comments --- .../src/occupancy-sensing-stub.cpp | 2 +- .../mode-select-server/mode-select-server.cpp | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp index ebc8780813cb3b..dcbb90ff659bcb 100644 --- a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -29,7 +29,7 @@ using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; static std::unique_ptr - gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1]; + gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; void emberAfOccupancySensingClusterInitCallback(EndpointId endpointId) { diff --git a/src/app/clusters/mode-select-server/mode-select-server.cpp b/src/app/clusters/mode-select-server/mode-select-server.cpp index a53bf4a71967e5..e9daf9e7ab64d9 100644 --- a/src/app/clusters/mode-select-server/mode-select-server.cpp +++ b/src/app/clusters/mode-select-server/mode-select-server.cpp @@ -49,7 +49,7 @@ using BootReasonType = GeneralDiagnostics::BootReasonEnum; static InteractionModel::Status verifyModeValue(const EndpointId endpointId, const uint8_t newMode); -ModeSelect::SupportedModesManager * sSupportedModesManager = nullptr; +static ModeSelect::SupportedModesManager * sSupportedModesManager = nullptr; const SupportedModesManager * ModeSelect::getSupportedModesManager() { @@ -82,6 +82,12 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteReadAttributePath & aPath, A if (ModeSelect::Attributes::SupportedModes::Id == aPath.mAttributeId) { + if (gSupportedModeManager == nullptr) + { + ChipLogError(Zcl, "ModeSelect: SupportedModesManager is NULL"); + aEncoder.EncodeEmptyList(); + return CHIP_NO_ERROR; + } const ModeSelect::SupportedModesManager::ModeOptionsProvider modeOptionsProvider = gSupportedModeManager->getModeOptionsProvider(aPath.mEndpointId); if (modeOptionsProvider.begin() == nullptr) @@ -115,8 +121,14 @@ bool emberAfModeSelectClusterChangeToModeCallback(CommandHandler * commandHandle uint8_t newMode = commandData.newMode; // Check that the newMode matches one of the supported options const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr; - Status checkSupportedModeStatus = - ModeSelect::getSupportedModesManager()->getModeOptionByMode(endpointId, newMode, &modeOptionPtr); + const ModeSelect::SupportedModesManager * gSupportedModeManager = ModeSelect::getSupportedModesManager(); + if (gSupportedModeManager == nullptr) + { + ChipLogError(Zcl, "ModeSelect: SupportedModesManager is NULL"); + commandHandler->AddStatus(commandPath, Status::Failure); + return true; + } + Status checkSupportedModeStatus = gSupportedModeManager->getModeOptionByMode(endpointId, newMode, &modeOptionPtr); if (Status::Success != checkSupportedModeStatus) { ChipLogProgress(Zcl, "ModeSelect: Failed to find the option with mode %u", newMode); @@ -276,5 +288,11 @@ static InteractionModel::Status verifyModeValue(const EndpointId endpointId, con return InteractionModel::Status::Success; } const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr; - return ModeSelect::getSupportedModesManager()->getModeOptionByMode(endpointId, newMode, &modeOptionPtr); + const ModeSelect::SupportedModesManager * gSupportedModeManager = ModeSelect::getSupportedModesManager(); + if (gSupportedModeManager == nullptr) + { + ChipLogError(Zcl, "ModeSelect: SupportedModesManager is NULL"); + return Status::Failure; + } + return gSupportedModeManager->getModeOptionByMode(endpointId, newMode, &modeOptionPtr); }