Skip to content

Commit

Permalink
Replace ReturnErrorCodeIf with VerifyOrReturnError (project-chip#36083)
Browse files Browse the repository at this point in the history
* 'ReturnErrorCodeIf(!$A, $B);' -> 'VerifyOrReturnError($A, $B);'

* 'ReturnErrorCodeIf($A == $B, $C);' -> 'VerifyOrReturnError($A != $B, $C);'

* 'ReturnErrorCodeIf($A != $B, $C);' -> 'VerifyOrReturnError($A == $B, $C);'

* 'ReturnErrorCodeIf($A < $B, $C);' -> 'VerifyOrReturnError($A >= $B, $C);'

* 'ReturnErrorCodeIf($A <= $B, $C);' -> 'VerifyOrReturnError($A > $B, $C);'

* 'ReturnErrorCodeIf($A > $B, $C);' -> 'VerifyOrReturnError($A <= $B, $C);'

* 'ReturnErrorCodeIf($A >= $B, $C);' -> 'VerifyOrReturnError($A < $B, $C);'

* 'ReturnErrorCodeIf($A($$$B), $C);' -> 'VerifyOrReturnError(!$A($$$B), $C);'

* 'ReturnErrorCodeIf($A, $B);' -> 'VerifyOrReturnError(!$A, $B);'

* Replace ReturnErrorCodeWithMetricIf with VerifyOrReturnErrorWithMetric

* Restyled by clang-format

* 'ReturnErrorCodeIf($A != $B && $C != $D, $Z);' --rewrite 'VerifyOrReturnError($A == $B || $C == $D, $Z);'

* 'ReturnErrorCodeIf($A == $B && $C == $D, $Z);' --rewrite 'VerifyOrReturnError($A != $B || $C != $D, $Z);'

* 'ReturnErrorCodeIf($A == $B || $C == $D, $Z);' --rewrite 'VerifyOrReturnError($A != $B && $C != $D, $Z);'

* 'ReturnErrorCodeIf($A || $B, $Z);' --rewrite 'VerifyOrReturnError(!($A) && !($B), $Z);'

This commit was manually optimized.

* 'ReturnErrorCodeIf($A && $B, $Z);' --rewrite 'VerifyOrReturnError(!($A) || !($B), $Z);'

This commit was manually optimized.

* Drop support for ReturnErrorCodeIf

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
arkq and restyled-commits authored Oct 18, 2024
1 parent edf3b8b commit 0060e0e
Show file tree
Hide file tree
Showing 160 changed files with 695 additions and 782 deletions.
4 changes: 2 additions & 2 deletions examples/bridge-app/asr/subdevice/SubDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(SubDevice * dev, c
{
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);

ReturnErrorCodeIf((attributeId != OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
Protocols::InteractionModel::Status::Failure);
VerifyOrReturnError((attributeId == OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
Protocols::InteractionModel::Status::Failure);
dev->SetOnOff(*buffer == 1);
return Protocols::InteractionModel::Status::Success;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(Device * dev, chip
{
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);

ReturnErrorCodeIf((attributeId != OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
Protocols::InteractionModel::Status::Failure);
VerifyOrReturnError((attributeId == OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
Protocols::InteractionModel::Status::Failure);
dev->SetOnOff(*buffer == 1);
return Protocols::InteractionModel::Status::Success;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(Device * dev, chip
{
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);

ReturnErrorCodeIf((attributeId != Clusters::OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
Protocols::InteractionModel::Status::Failure);
VerifyOrReturnError((attributeId == Clusters::OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
Protocols::InteractionModel::Status::Failure);
dev->SetOnOff(*buffer == 1);
return Protocols::InteractionModel::Status::Success;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace chip;
CHIP_ERROR WaitForCommissioneeCommand::RunCommand()
{
chip::FabricIndex fabricIndex = CurrentCommissioner().GetFabricIndex();
ReturnErrorCodeIf(fabricIndex == chip::kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(fabricIndex != chip::kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);

if (mExpireExistingSession.ValueOr(true))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CHIP_ERROR EvseTargetsDelegate::LoadTargets()

Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
uint16_t length = GetTlvSizeUpperBound();
ReturnErrorCodeIf(!backingBuffer.Calloc(length), CHIP_ERROR_NO_MEMORY);
VerifyOrReturnError(backingBuffer.Calloc(length), CHIP_ERROR_NO_MEMORY);

CHIP_ERROR err = mpTargetStore->SyncGetKeyValue(spEvseTargetsKeyName, backingBuffer.Get(), length);
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
Expand Down Expand Up @@ -390,7 +390,7 @@ EvseTargetsDelegate::SaveTargets(DataModel::List<const Structs::ChargingTargetSc
uint16_t total = GetTlvSizeUpperBound();

Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
ReturnErrorCodeIf(!backingBuffer.Calloc(total), CHIP_ERROR_NO_MEMORY);
VerifyOrReturnError(backingBuffer.Calloc(total), CHIP_ERROR_NO_MEMORY);
TLV::ScopedBufferTLVWriter writer(std::move(backingBuffer), total);

TLV::TLVType arrayType;
Expand Down
24 changes: 12 additions & 12 deletions examples/persistent-storage/KeyValueStorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ CHIP_ERROR TestEmptyString()
size_t read_size;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
ReturnErrorCodeIf(strcmp(kTestValue, read_value) != 0, CHIP_ERROR_INTERNAL);
ReturnErrorCodeIf(read_size != sizeof(kTestValue), CHIP_ERROR_INTERNAL);
VerifyOrReturnError(strcmp(kTestValue, read_value) == 0, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(read_size == sizeof(kTestValue), CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}
Expand All @@ -69,8 +69,8 @@ CHIP_ERROR TestString()
size_t read_size;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
ReturnErrorCodeIf(strcmp(kTestValue, read_value) != 0, CHIP_ERROR_INTERNAL);
ReturnErrorCodeIf(read_size != sizeof(kTestValue), CHIP_ERROR_INTERNAL);
VerifyOrReturnError(strcmp(kTestValue, read_value) == 0, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(read_size == sizeof(kTestValue), CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}
Expand All @@ -82,7 +82,7 @@ CHIP_ERROR TestUint32()
uint32_t read_value;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
ReturnErrorCodeIf(kTestValue != read_value, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(kTestValue == read_value, CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}
Expand All @@ -94,7 +94,7 @@ CHIP_ERROR TestArray()
uint32_t read_value[5];
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
ReturnErrorCodeIf(memcmp(kTestValue, read_value, sizeof(kTestValue)) != 0, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(memcmp(kTestValue, read_value, sizeof(kTestValue)) == 0, CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}
Expand All @@ -111,8 +111,8 @@ CHIP_ERROR TestStruct()
SomeStruct read_value;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
ReturnErrorCodeIf(kTestValue.value1 != read_value.value1, CHIP_ERROR_INTERNAL);
ReturnErrorCodeIf(kTestValue.value2 != read_value.value2, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(kTestValue.value1 == read_value.value1, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(kTestValue.value2 == read_value.value2, CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}
Expand All @@ -125,7 +125,7 @@ CHIP_ERROR TestUpdateValue()
{
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, i));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
ReturnErrorCodeIf(i != read_value, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(i == read_value, CHIP_ERROR_INTERNAL);
}
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
Expand All @@ -142,9 +142,9 @@ CHIP_ERROR TestMultiRead()
size_t read_size;
// Returns buffer too small for all but the last read.
CHIP_ERROR error = KeyValueStoreMgr().Get(kTestKey, &read_value, sizeof(read_value), &read_size, i * sizeof(uint32_t));
ReturnErrorCodeIf(error != (i < 4 ? CHIP_ERROR_BUFFER_TOO_SMALL : CHIP_NO_ERROR), error);
ReturnErrorCodeIf(read_size != sizeof(read_value), CHIP_ERROR_INTERNAL);
ReturnErrorCodeIf(kTestValue[i] != read_value, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(error == (i < 4 ? CHIP_ERROR_BUFFER_TOO_SMALL : CHIP_NO_ERROR), error);
VerifyOrReturnError(read_size == sizeof(read_value), CHIP_ERROR_INTERNAL);
VerifyOrReturnError(kTestValue[i] == read_value, CHIP_ERROR_INTERNAL);
}
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetFirmwareInformation(MutableByte

CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetDeviceAttestationCert(MutableByteSpan & out_buffer)
{
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
VerifyOrReturnError(out_buffer.size() >= mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer);
return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer)
{
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
VerifyOrReturnError(out_buffer.size() >= mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,17 @@ CHIP_ERROR DeviceAttestationCredsCC32XX::GetFirmwareInformation(MutableByteSpan

CHIP_ERROR DeviceAttestationCredsCC32XX::GetDeviceAttestationCert(MutableByteSpan & out_buffer)
{
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
VerifyOrReturnError(out_buffer.size() >= mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer);
return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceAttestationCredsCC32XX::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer)
{
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
VerifyOrReturnError(out_buffer.size() >= mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ static void wfx_rsi_save_ap_info(void) // translation
**********************************************************************************************/
static sl_status_t wfx_rsi_do_join(void)
{
ReturnErrorCodeIf((wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)), SL_STATUS_IN_PROGRESS);
VerifyOrReturnError(!(wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)), SL_STATUS_IN_PROGRESS);
sl_status_t status = SL_STATUS_OK;
sl_wifi_client_configuration_t ap;
memset(&ap, 0, sizeof(ap));
Expand Down Expand Up @@ -680,7 +680,7 @@ static sl_status_t wfx_rsi_do_join(void)
status = sl_wifi_connect(SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms);
// sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress
// after the initial scan is done, the scan does not check for SSID
ReturnErrorCodeIf((status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS), status);
VerifyOrReturnError(status != SL_STATUS_OK && status != SL_STATUS_IN_PROGRESS, status);

// failure only happens when the firmware returns an error
ChipLogError(DeviceLayer, "wfx_rsi_do_join: sl_wifi_connect failed: 0x%lx", static_cast<uint32_t>(status));
Expand Down
6 changes: 3 additions & 3 deletions examples/platform/silabs/provision/ProvisionStorageFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CHIP_ERROR DecodeTotal(Encoding::Buffer & reader, uint16_t & total)
ReturnErrorOnFailure(reader.Get(sz));
total = (0xffff == sz) ? sizeof(uint16_t) : sz;
reader.in = reader.begin + total;
ReturnErrorCodeIf(reader.in > reader.end, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(reader.in <= reader.end, CHIP_ERROR_INTERNAL);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
{
// New entry
size_t temp_total = found.offset;
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
// Copy entry
ReturnErrorOnFailure(in.Get(page + temp_total, in.Size()));
// Update total
Expand All @@ -138,7 +138,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
{
// Size change, move to the end
uint16_t temp_total = total - found.encoded_size;
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
// Remove the entry
memmove(page + found.offset, page + found.offset + found.encoded_size, temp_total);
// Add the entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MediaCommandBase : public MediaBase
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");

auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);

sResponseCallback = responseCallback;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MediaReadBase : public MediaBase
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");

auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);

MediaClusterBase cluster(*deviceProxy->GetExchangeManager(), deviceProxy->GetSecureSession().Value(), mTvEndpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MediaSubscriptionBase : public MediaBase
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");

auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);

MediaClusterBase cluster(*deviceProxy->GetExchangeManager(), deviceProxy->GetSecureSession().Value(), mTvEndpoint);

Expand Down
4 changes: 2 additions & 2 deletions src/access/AccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ CHIP_ERROR AccessControl::CreateEntry(const SubjectDescriptor * subjectDescripto

VerifyOrReturnError((count + 1) <= maxCount, CHIP_ERROR_BUFFER_TOO_SMALL);

ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);

size_t i = 0;
ReturnErrorOnFailure(mDelegate->CreateEntry(&i, entry, &fabric));
Expand All @@ -250,7 +250,7 @@ CHIP_ERROR AccessControl::UpdateEntry(const SubjectDescriptor * subjectDescripto
const Entry & entry)
{
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
ReturnErrorOnFailure(mDelegate->UpdateEntry(index, entry, &fabric));
NotifyEntryChanged(subjectDescriptor, fabric, index, &entry, EntryListener::ChangeType::kUpdated);
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/access/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class AccessControl
*/
CHIP_ERROR CreateEntry(size_t * index, const Entry & entry, FabricIndex * fabricIndex = nullptr)
{
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
return mDelegate->CreateEntry(index, entry, fabricIndex);
}
Expand Down Expand Up @@ -551,7 +551,7 @@ class AccessControl
*/
CHIP_ERROR UpdateEntry(size_t index, const Entry & entry, const FabricIndex * fabricIndex = nullptr)
{
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
return mDelegate->UpdateEntry(index, entry, fabricIndex);
}
Expand Down
4 changes: 2 additions & 2 deletions src/access/examples/ExampleAccessControlDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ CHIP_ERROR CopyViaInterface(const Entry & entry, EntryStorage & storage)

size_t subjectCount = 0;
ReturnErrorOnFailure(entry.GetSubjectCount(subjectCount));
ReturnErrorCodeIf(subjectCount > EntryStorage::kMaxSubjects, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(subjectCount <= EntryStorage::kMaxSubjects, CHIP_ERROR_BUFFER_TOO_SMALL);
for (size_t i = 0; i < subjectCount; ++i)
{
NodeId subject = kUndefinedNodeId;
Expand All @@ -919,7 +919,7 @@ CHIP_ERROR CopyViaInterface(const Entry & entry, EntryStorage & storage)

size_t targetCount = 0;
ReturnErrorOnFailure(entry.GetTargetCount(targetCount));
ReturnErrorCodeIf(targetCount > EntryStorage::kMaxTargets, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(targetCount <= EntryStorage::kMaxTargets, CHIP_ERROR_BUFFER_TOO_SMALL);
for (size_t i = 0; i < targetCount; ++i)
{
Target target;
Expand Down
16 changes: 8 additions & 8 deletions src/access/tests/TestAccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,30 +662,30 @@ CHIP_ERROR CompareEntry(const Entry & entry, const EntryData & entryData)
{
AuthMode authMode = AuthMode::kNone;
ReturnErrorOnFailure(entry.GetAuthMode(authMode));
ReturnErrorCodeIf(authMode != entryData.authMode, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(authMode == entryData.authMode, CHIP_ERROR_INCORRECT_STATE);
FabricIndex fabricIndex = kUndefinedFabricIndex;
ReturnErrorOnFailure(entry.GetFabricIndex(fabricIndex));
ReturnErrorCodeIf(fabricIndex != entryData.fabricIndex, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(fabricIndex == entryData.fabricIndex, CHIP_ERROR_INCORRECT_STATE);
Privilege privilege = Privilege::kView;
ReturnErrorOnFailure(entry.GetPrivilege(privilege));
ReturnErrorCodeIf(privilege != entryData.privilege, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(privilege == entryData.privilege, CHIP_ERROR_INCORRECT_STATE);
size_t subjectCount = 0;
ReturnErrorOnFailure(entry.GetSubjectCount(subjectCount));
ReturnErrorCodeIf(subjectCount != entryData.GetSubjectCount(), CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(subjectCount == entryData.GetSubjectCount(), CHIP_ERROR_INCORRECT_STATE);
for (size_t i = 0; i < subjectCount; ++i)
{
NodeId subject = kUndefinedNodeId;
ReturnErrorOnFailure(entry.GetSubject(i, subject));
ReturnErrorCodeIf(subject != entryData.subjects[i], CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(subject == entryData.subjects[i], CHIP_ERROR_INCORRECT_STATE);
}
size_t targetCount = 0;
ReturnErrorOnFailure(entry.GetTargetCount(targetCount));
ReturnErrorCodeIf(targetCount != entryData.GetTargetCount(), CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(targetCount == entryData.GetTargetCount(), CHIP_ERROR_INCORRECT_STATE);
for (size_t i = 0; i < targetCount; ++i)
{
Target target;
ReturnErrorOnFailure(entry.GetTarget(i, target));
ReturnErrorCodeIf(target != entryData.targets[i], CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(target == entryData.targets[i], CHIP_ERROR_INCORRECT_STATE);
}
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -724,7 +724,7 @@ CHIP_ERROR CompareAccessControl(AccessControl & ac, const EntryData * entryData,
ReturnErrorOnFailure(ac.ReadEntry(i, entry));
ReturnErrorOnFailure(CompareEntry(entry, *entryData));
}
ReturnErrorCodeIf(ac.ReadEntry(count, entry) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(ac.ReadEntry(count, entry) != CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
return CHIP_NO_ERROR;
}

Expand Down
Loading

0 comments on commit 0060e0e

Please sign in to comment.