diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 9c223fd9d2a846..15d59e696d1a3c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1513,10 +1513,9 @@ void BasicFailure(void * context, uint8_t status) #if CHIP_DEVICE_CONFIG_ENABLE_MDNS void DeviceCommissioner::OnNodeIdResolved(const chip::Mdns::ResolvedNodeData & nodeData) { - Device * device = nullptr; if (mDeviceBeingPaired < kNumMaxActiveDevices) { - device = &mActiveDevices[mDeviceBeingPaired]; + Device * device = &mActiveDevices[mDeviceBeingPaired]; if (device->GetDeviceId() == nodeData.mPeerId.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) { AdvanceCommissioningStage(CHIP_NO_ERROR); @@ -1527,16 +1526,13 @@ void DeviceCommissioner::OnNodeIdResolved(const chip::Mdns::ResolvedNodeData & n void DeviceCommissioner::OnNodeIdResolutionFailed(const chip::PeerId & peer, CHIP_ERROR error) { - Device * device = nullptr; - if (mDeviceBeingPaired >= kNumMaxActiveDevices) - { - return; - } - - device = &mActiveDevices[mDeviceBeingPaired]; - if (device->GetDeviceId() == peer.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + if (mDeviceBeingPaired < kNumMaxActiveDevices) { - OnSessionEstablishmentError(error); + Device * device = &mActiveDevices[mDeviceBeingPaired]; + if (device->GetDeviceId() == peer.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + { + OnSessionEstablishmentError(error); + } } DeviceController::OnNodeIdResolutionFailed(peer, error); }