@@ -49,7 +49,7 @@ using BootReasonType = GeneralDiagnostics::BootReasonEnum;
49
49
50
50
static InteractionModel::Status verifyModeValue (const EndpointId endpointId, const uint8_t newMode);
51
51
52
- ModeSelect::SupportedModesManager * sSupportedModesManager = nullptr ;
52
+ static ModeSelect::SupportedModesManager * sSupportedModesManager = nullptr ;
53
53
54
54
const SupportedModesManager * ModeSelect::getSupportedModesManager ()
55
55
{
@@ -82,6 +82,12 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
82
82
83
83
if (ModeSelect::Attributes::SupportedModes::Id == aPath.mAttributeId )
84
84
{
85
+ if (gSupportedModeManager == nullptr )
86
+ {
87
+ ChipLogError (Zcl, " ModeSelect: SupportedModesManager is NULL" );
88
+ aEncoder.EncodeEmptyList ();
89
+ return CHIP_NO_ERROR;
90
+ }
85
91
const ModeSelect::SupportedModesManager::ModeOptionsProvider modeOptionsProvider =
86
92
gSupportedModeManager ->getModeOptionsProvider (aPath.mEndpointId );
87
93
if (modeOptionsProvider.begin () == nullptr )
@@ -115,8 +121,14 @@ bool emberAfModeSelectClusterChangeToModeCallback(CommandHandler * commandHandle
115
121
uint8_t newMode = commandData.newMode ;
116
122
// Check that the newMode matches one of the supported options
117
123
const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr;
118
- Status checkSupportedModeStatus =
119
- ModeSelect::getSupportedModesManager ()->getModeOptionByMode (endpointId, newMode, &modeOptionPtr);
124
+ const ModeSelect::SupportedModesManager * gSupportedModeManager = ModeSelect::getSupportedModesManager ();
125
+ if (gSupportedModeManager == nullptr )
126
+ {
127
+ ChipLogError (Zcl, " ModeSelect: SupportedModesManager is NULL" );
128
+ commandHandler->AddStatus (commandPath, Status::Failure);
129
+ return true ;
130
+ }
131
+ Status checkSupportedModeStatus = gSupportedModeManager ->getModeOptionByMode (endpointId, newMode, &modeOptionPtr);
120
132
if (Status::Success != checkSupportedModeStatus)
121
133
{
122
134
ChipLogProgress (Zcl, " ModeSelect: Failed to find the option with mode %u" , newMode);
@@ -276,5 +288,11 @@ static InteractionModel::Status verifyModeValue(const EndpointId endpointId, con
276
288
return InteractionModel::Status::Success;
277
289
}
278
290
const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr;
279
- return ModeSelect::getSupportedModesManager ()->getModeOptionByMode (endpointId, newMode, &modeOptionPtr);
291
+ const ModeSelect::SupportedModesManager * gSupportedModeManager = ModeSelect::getSupportedModesManager ();
292
+ if (gSupportedModeManager == nullptr )
293
+ {
294
+ ChipLogError (Zcl, " ModeSelect: SupportedModesManager is NULL" );
295
+ return Status::Failure;
296
+ }
297
+ return gSupportedModeManager ->getModeOptionByMode (endpointId, newMode, &modeOptionPtr);
280
298
}
0 commit comments