Skip to content

Commit 8fbcc70

Browse files
authored
nodiscard ChipError Batch project-chip#7: access, ble, credentials (project-chip#41865)
* Batch project-chip#7 nodiscard errors: access, ble, credentials * Clang tidy
1 parent 7a7670f commit 8fbcc70

File tree

10 files changed

+49
-47
lines changed

10 files changed

+49
-47
lines changed

src/access/examples/ExampleAccessControlDelegate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class EntryDelegate : public Entry::Delegate
602602
{
603603
ReturnErrorOnFailure(EnsureStorageInPool());
604604
size_t count = 0;
605-
GetSubjectCount(count);
605+
TEMPORARY_RETURN_IGNORED GetSubjectCount(count);
606606
if (count < EntryStorage::kMaxSubjects)
607607
{
608608
CHIP_ERROR err = mStorage->mSubjects[count].Add(subject);
@@ -619,7 +619,7 @@ class EntryDelegate : public Entry::Delegate
619619
{
620620
ReturnErrorOnFailure(EnsureStorageInPool());
621621
size_t count = 0;
622-
GetSubjectCount(count);
622+
TEMPORARY_RETURN_IGNORED GetSubjectCount(count);
623623
if (index < count)
624624
{
625625
// The storage at the specified index will be deleted by copying any subsequent storage
@@ -675,7 +675,7 @@ class EntryDelegate : public Entry::Delegate
675675
{
676676
ReturnErrorOnFailure(EnsureStorageInPool());
677677
size_t count = 0;
678-
GetTargetCount(count);
678+
TEMPORARY_RETURN_IGNORED GetTargetCount(count);
679679
if (count < EntryStorage::kMaxTargets)
680680
{
681681
CHIP_ERROR err = mStorage->mTargets[count].Add(target);
@@ -692,7 +692,7 @@ class EntryDelegate : public Entry::Delegate
692692
{
693693
ReturnErrorOnFailure(EnsureStorageInPool());
694694
size_t count = 0;
695-
GetTargetCount(count);
695+
TEMPORARY_RETURN_IGNORED GetTargetCount(count);
696696
if (index < count)
697697
{
698698
// The storage at the specified index will be deleted by copying any subsequent storage
@@ -732,7 +732,7 @@ class EntryDelegate : public Entry::Delegate
732732
if (mStorage == &storage)
733733
{
734734
// Best effort, OK if it fails.
735-
EnsureStorageInPool();
735+
TEMPORARY_RETURN_IGNORED EnsureStorageInPool();
736736
}
737737
}
738738

src/ble/BLEEndPoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void BLEEndPoint::ReleaseBleConnection()
445445
if (mConnStateFlags.Has(ConnectionStateFlag::kAutoClose))
446446
{
447447
ChipLogProgress(Ble, "Auto-closing end point's BLE connection.");
448-
mBle->mPlatformDelegate->CloseConnection(mConnObj);
448+
TEMPORARY_RETURN_IGNORED mBle->mPlatformDelegate->CloseConnection(mConnObj);
449449
}
450450
else
451451
{
@@ -876,7 +876,7 @@ CHIP_ERROR BLEEndPoint::DoSendStandAloneAck()
876876
ChipLogDebugBleEndPoint(Ble, "entered DoSendStandAloneAck; sending stand-alone ack");
877877

878878
// Encode and transmit stand-alone ack.
879-
mBtpEngine.EncodeStandAloneAck(mAckToSend);
879+
ReturnErrorOnFailure(mBtpEngine.EncodeStandAloneAck(mAckToSend));
880880
ReturnErrorOnFailure(SendCharacteristic(mAckToSend.Retain()));
881881

882882
// Reset local receive window counter.

src/ble/BleLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ CHIP_ERROR BleLayer::NewBleEndPoint(BLEEndPoint ** retEndPoint, BLE_CONNECTION_O
431431
return CHIP_ERROR_ENDPOINT_POOL_FULL;
432432
}
433433

434-
endPoint->Init(this, connObj, role, autoClose);
434+
TEMPORARY_RETURN_IGNORED endPoint->Init(this, connObj, role, autoClose);
435435
endPoint->mBleTransport = mBleTransport;
436436

437437
*retEndPoint = endPoint;

src/credentials/CHIPCert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ void InitNetworkIdentitySubject(ChipDN & name)
14891489
{
14901490
name.Clear();
14911491
CHIP_ERROR err = name.AddAttribute_CommonName(kNetworkIdentityCN, /* not printable */ false);
1492-
VerifyOrDie(err == CHIP_NO_ERROR); // AddAttribute can't fail in this case
1492+
SuccessOrDie(err); // AddAttribute can't fail in this case
14931493
}
14941494

14951495
static CHIP_ERROR CalculateKeyIdentifierSha256(const P256PublicKeySpan & publicKey, MutableCertificateKeyId outKeyId)

src/credentials/CHIPCertToX509.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,17 +603,18 @@ static CHIP_ERROR DecodeConvertCert(TLVReader & reader, ASN1Writer & writer, ASN
603603
ASN1_START_SEQUENCE
604604
{
605605
// tbsCertificate TBSCertificate,
606-
reader.Next();
606+
TEMPORARY_RETURN_IGNORED reader.Next();
607607
if (reader.GetTag() == ContextTag(kTag_EllipticCurvePublicKey))
608608
{
609609
// If the struct starts with the ec-pub-key we're dealing with a
610610
// Network (Client) Identity in compact-pdc-identity format.
611-
DecodeConvertTBSCertCompactIdentity(reader, tbsWriter, certData);
611+
err = DecodeConvertTBSCertCompactIdentity(reader, tbsWriter, certData);
612612
}
613613
else
614614
{
615-
ReturnErrorOnFailure(DecodeConvertTBSCert(reader, tbsWriter, certData));
615+
err = DecodeConvertTBSCert(reader, tbsWriter, certData);
616616
}
617+
ReturnErrorOnFailure(err);
617618

618619
// signatureAlgorithm AlgorithmIdentifier
619620
// AlgorithmIdentifier ::= SEQUENCE

src/credentials/FabricTable.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void FabricInfo::operator=(FabricInfo && other)
154154
mVendorId = other.mVendorId;
155155
mShouldAdvertiseIdentity = other.mShouldAdvertiseIdentity;
156156

157-
SetFabricLabel(other.GetFabricLabel());
157+
TEMPORARY_RETURN_IGNORED SetFabricLabel(other.GetFabricLabel());
158158

159159
// Transfer ownership of operational keypair (if it was nullptr, it stays that way).
160160
mOperationalKey = other.mOperationalKey;
@@ -911,7 +911,7 @@ FabricTable::AddOrUpdateInner(FabricIndex fabricIndex, bool isAddition, Crypto::
911911
ReturnErrorOnFailure(fabricEntry->Init(newFabricInfo));
912912

913913
// Set the label, matching add/update semantics of empty/existing.
914-
fabricEntry->SetFabricLabel(fabricLabel);
914+
TEMPORARY_RETURN_IGNORED fabricEntry->SetFabricLabel(fabricLabel);
915915

916916
if (isAddition)
917917
{
@@ -1018,7 +1018,7 @@ CHIP_ERROR FabricTable::Delete(FabricIndex fabricIndex)
10181018
// If StoreFabricIndexInfo fails here, that's probably OK. When we try to
10191019
// read things from storage later we will realize there is nothing for this
10201020
// index.
1021-
StoreFabricIndexInfo();
1021+
TEMPORARY_RETURN_IGNORED StoreFabricIndexInfo();
10221022

10231023
// If we ever start moving the FabricInfo entries around in the array on
10241024
// delete, we should update DeleteAllFabrics to handle that.
@@ -1067,7 +1067,7 @@ void FabricTable::DeleteAllFabrics()
10671067

10681068
for (auto & fabric : *this)
10691069
{
1070-
Delete(fabric.GetFabricIndex());
1070+
TEMPORARY_RETURN_IGNORED Delete(fabric.GetFabricIndex());
10711071
}
10721072
}
10731073

@@ -1096,7 +1096,7 @@ CHIP_ERROR FabricTable::Init(const FabricTable::InitParams & initParams)
10961096
// Time is unknown during incoming certificate validation for CASE and
10971097
// current time is also unknown, the certificate validity policy will see
10981098
// this condition and can act appropriately.
1099-
mLastKnownGoodTime.Init(mStorage);
1099+
TEMPORARY_RETURN_IGNORED mLastKnownGoodTime.Init(mStorage);
11001100

11011101
uint8_t buf[IndexInfoTLVMaxSize()];
11021102
uint16_t size = sizeof(buf);
@@ -1328,19 +1328,19 @@ CHIP_ERROR FabricTable::StoreFabricIndexInfo() const
13281328

13291329
if (mNextAvailableFabricIndex.HasValue())
13301330
{
1331-
writer.Put(kNextAvailableFabricIndexTag, mNextAvailableFabricIndex.Value());
1331+
TEMPORARY_RETURN_IGNORED writer.Put(kNextAvailableFabricIndexTag, mNextAvailableFabricIndex.Value());
13321332
}
13331333
else
13341334
{
1335-
writer.PutNull(kNextAvailableFabricIndexTag);
1335+
TEMPORARY_RETURN_IGNORED writer.PutNull(kNextAvailableFabricIndexTag);
13361336
}
13371337

13381338
TLV::TLVType innerContainerType;
13391339
ReturnErrorOnFailure(writer.StartContainer(kFabricIndicesTag, TLV::kTLVType_Array, innerContainerType));
13401340
// Only enumerate the fabrics that are initialized.
13411341
for (const auto & fabric : *this)
13421342
{
1343-
writer.Put(TLV::AnonymousTag(), fabric.GetFabricIndex());
1343+
TEMPORARY_RETURN_IGNORED writer.Put(TLV::AnonymousTag(), fabric.GetFabricIndex());
13441344
}
13451345
ReturnErrorOnFailure(writer.EndContainer(innerContainerType));
13461346
ReturnErrorOnFailure(writer.EndContainer(outerType));
@@ -1500,7 +1500,7 @@ CHIP_ERROR FabricTable::GetCommitMarker(CommitMarker & outCommitMarker)
15001500

15011501
void FabricTable::ClearCommitMarker()
15021502
{
1503-
mStorage->SyncDeleteKeyValue(DefaultStorageKeyAllocator::FabricTableCommitMarkerKey().KeyName());
1503+
TEMPORARY_RETURN_IGNORED mStorage->SyncDeleteKeyValue(DefaultStorageKeyAllocator::FabricTableCommitMarkerKey().KeyName());
15041504
}
15051505

15061506
bool FabricTable::HasOperationalKeyForFabric(FabricIndex fabricIndex) const
@@ -1760,7 +1760,7 @@ CHIP_ERROR FabricTable::AddNewPendingFabricCommon(const ByteSpan & noc, const By
17601760

17611761
// Notify that NOC was added (at least transiently)
17621762
*outNewFabricIndex = fabricIndexToUse;
1763-
NotifyFabricUpdated(fabricIndexToUse);
1763+
TEMPORARY_RETURN_IGNORED NotifyFabricUpdated(fabricIndexToUse);
17641764

17651765
return CHIP_NO_ERROR;
17661766
}
@@ -1845,7 +1845,7 @@ CHIP_ERROR FabricTable::UpdatePendingFabricCommon(FabricIndex fabricIndex, const
18451845
mStateFlags.Set(StateFlags::kIsPendingFabricDataPresent);
18461846

18471847
// Notify that NOC was updated (at least transiently)
1848-
NotifyFabricUpdated(fabricIndex);
1848+
TEMPORARY_RETURN_IGNORED NotifyFabricUpdated(fabricIndex);
18491849

18501850
return CHIP_NO_ERROR;
18511851
}
@@ -2061,13 +2061,13 @@ CHIP_ERROR FabricTable::CommitPendingFabricData()
20612061
{
20622062
// Blow-away everything if we got past any storage, even on Update: system state is broken
20632063
// TODO: Develop a way to properly revert in the future, but this is very difficult
2064-
Delete(fabricIndexBeingCommitted);
2064+
TEMPORARY_RETURN_IGNORED Delete(fabricIndexBeingCommitted);
20652065

20662066
RevertPendingFabricData();
20672067
}
20682068
else
20692069
{
2070-
NotifyFabricCommitted(fabricIndexBeingCommitted);
2070+
TEMPORARY_RETURN_IGNORED NotifyFabricCommitted(fabricIndexBeingCommitted);
20712071
}
20722072

20732073
// Clear commit marker no matter what: if we got here, there was no reboot and previous clean-ups
@@ -2094,7 +2094,7 @@ void FabricTable::RevertPendingFabricData()
20942094
mOpCertStore->RevertPendingOpCerts();
20952095
}
20962096

2097-
mLastKnownGoodTime.RevertPendingLastKnownGoodChipEpochTime();
2097+
TEMPORARY_RETURN_IGNORED mLastKnownGoodTime.RevertPendingLastKnownGoodChipEpochTime();
20982098

20992099
mStateFlags.ClearAll();
21002100
mFabricIndexWithPendingState = kUndefinedFabricIndex;
@@ -2119,7 +2119,7 @@ void FabricTable::RevertPendingOpCertsExceptRoot()
21192119
if (mStateFlags.Has(StateFlags::kIsAddPending))
21202120
{
21212121
// If we have a pending add, let's make sure to kill the pending fabric metadata and return it to viable state.
2122-
Delete(mFabricIndexWithPendingState);
2122+
TEMPORARY_RETURN_IGNORED Delete(mFabricIndexWithPendingState);
21232123
}
21242124

21252125
mStateFlags.Clear(StateFlags::kIsAddPending);

src/credentials/FabricTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class DLL_EXPORT FabricTable
439439
// TODO this #if CONFIG_BUILD_FOR_HOST_UNIT_TEST is temporary. There is a change incoming soon
440440
// that will allow triggering NOC update directly.
441441
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
442-
void SendUpdateFabricNotificationForTest(FabricIndex fabricIndex) { NotifyFabricUpdated(fabricIndex); }
442+
void SendUpdateFabricNotificationForTest(FabricIndex fabricIndex) { TEMPORARY_RETURN_IGNORED NotifyFabricUpdated(fabricIndex); }
443443
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
444444

445445
/**

src/credentials/GenerateChipX509Cert.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ CHIP_ERROR EncodeNetworkIdentityTBSCert(const P256PublicKey & pubkey, ASN1Writer
423423
{
424424
ASN1_START_SEQUENCE
425425
{
426-
EncodeIsCAExtension(kNotCACert, writer);
427-
EncodeKeyUsageExtension(KeyUsageFlags::kDigitalSignature, writer);
428-
EncodeExtKeyUsageExtension({ kOID_KeyPurpose_ClientAuth, kOID_KeyPurpose_ServerAuth }, writer);
426+
TEMPORARY_RETURN_IGNORED EncodeIsCAExtension(kNotCACert, writer);
427+
TEMPORARY_RETURN_IGNORED EncodeKeyUsageExtension(KeyUsageFlags::kDigitalSignature, writer);
428+
TEMPORARY_RETURN_IGNORED EncodeExtKeyUsageExtension({ kOID_KeyPurpose_ClientAuth, kOID_KeyPurpose_ServerAuth },
429+
writer);
429430
}
430431
ASN1_END_SEQUENCE;
431432
}

src/credentials/GroupDataProviderImpl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveGroupInfoAt(chip::FabricIndex fabric_ind
993993
{
994994
break;
995995
}
996-
endpoint.Delete(mStorage);
996+
TEMPORARY_RETURN_IGNORED endpoint.Delete(mStorage);
997997
endpoint.endpoint_id = endpoint.next;
998998
}
999999

@@ -1105,7 +1105,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoint(chip::FabricIndex fabric_index,
11051105
VerifyOrReturnError(endpoint.Find(mStorage, fabric, group, endpoint_id), CHIP_ERROR_NOT_FOUND);
11061106

11071107
// Existing endpoint
1108-
endpoint.Delete(mStorage);
1108+
TEMPORARY_RETURN_IGNORED endpoint.Delete(mStorage);
11091109

11101110
if (endpoint.first)
11111111
{
@@ -1331,7 +1331,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoints(chip::FabricIndex fabric_index
13311331
while (endpoint_index < group.endpoint_count)
13321332
{
13331333
ReturnErrorOnFailure(endpoint.Load(mStorage));
1334-
endpoint.Delete(mStorage);
1334+
TEMPORARY_RETURN_IGNORED endpoint.Delete(mStorage);
13351335
endpoint.endpoint_id = endpoint.next;
13361336
endpoint_index++;
13371337
}
@@ -1459,7 +1459,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveGroupKeys(chip::FabricIndex fabric_index
14591459
{
14601460
break;
14611461
}
1462-
map.Delete(mStorage);
1462+
TEMPORARY_RETURN_IGNORED map.Delete(mStorage);
14631463
map.id = map.next;
14641464
}
14651465

@@ -1627,7 +1627,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveKeySet(chip::FabricIndex fabric_index, u
16271627
uint16_t original_count = fabric.map_count;
16281628
for (uint16_t i = 0; i < original_count; ++i)
16291629
{
1630-
fabric.Load(mStorage);
1630+
TEMPORARY_RETURN_IGNORED fabric.Load(mStorage);
16311631
size_t idx = map.Find(mStorage, fabric, target_id);
16321632
if (idx == std::numeric_limits<size_t>::max())
16331633
{
@@ -1636,7 +1636,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveKeySet(chip::FabricIndex fabric_index, u
16361636
// NOTE: It's unclear what should happen here if we have removed the key set
16371637
// and possibly some mappings before failing. For now, ignoring errors, but
16381638
// open to suggestsions for the correct behavior.
1639-
RemoveGroupKeyAt(fabric_index, idx);
1639+
TEMPORARY_RETURN_IGNORED RemoveGroupKeyAt(fabric_index, idx);
16401640
}
16411641
return CHIP_NO_ERROR;
16421642
}
@@ -1706,14 +1706,14 @@ CHIP_ERROR GroupDataProviderImpl::RemoveFabric(chip::FabricIndex fabric_index)
17061706

17071707
for (size_t i = 0; i < fabric.map_count; i++)
17081708
{
1709-
RemoveGroupKeyAt(fabric_index, fabric.map_count - i - 1);
1709+
TEMPORARY_RETURN_IGNORED RemoveGroupKeyAt(fabric_index, fabric.map_count - i - 1);
17101710
}
17111711

17121712
// Remove group info
17131713

17141714
for (size_t i = 0; i < fabric.group_count; i++)
17151715
{
1716-
RemoveGroupInfoAt(fabric_index, fabric.group_count - i - 1);
1716+
TEMPORARY_RETURN_IGNORED RemoveGroupInfoAt(fabric_index, fabric.group_count - i - 1);
17171717
}
17181718

17191719
// Remove Keysets
@@ -1728,7 +1728,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveFabric(chip::FabricIndex fabric_index)
17281728
{
17291729
break;
17301730
}
1731-
RemoveKeySet(fabric_index, keyset.keyset_id);
1731+
TEMPORARY_RETURN_IGNORED RemoveKeySet(fabric_index, keyset.keyset_id);
17321732
keyset.keyset_id = keyset.next;
17331733
keyset_count++;
17341734
}
@@ -1926,7 +1926,7 @@ bool GroupDataProviderImpl::GroupSessionIteratorImpl::Next(GroupSession & output
19261926
KeySetData keyset;
19271927
VerifyOrReturnError(keyset.Find(mProvider.mStorage, fabric, mapping.keyset_id), false);
19281928

1929-
if (mKeyIndex >= keyset.keys_count)
1929+
if (mKeyIndex >= keyset.keys_count || (mKeyIndex >= KeySet::kEpochKeysMax))
19301930
{
19311931
// No more keys in current keyset, try next
19321932
mMapping = mapping.next;
@@ -1938,7 +1938,7 @@ bool GroupDataProviderImpl::GroupSessionIteratorImpl::Next(GroupSession & output
19381938
Crypto::GroupOperationalCredentials & creds = keyset.operational_keys[mKeyIndex++];
19391939
if (creds.hash == mSessionId)
19401940
{
1941-
mGroupKeyContext.Initialize(creds.encryption_key, mSessionId, creds.privacy_key);
1941+
TEMPORARY_RETURN_IGNORED mGroupKeyContext.Initialize(creds.encryption_key, mSessionId, creds.privacy_key);
19421942
output.fabric_index = fabric.fabric_index;
19431943
output.group_id = mapping.group_id;
19441944
output.security_policy = keyset.policy;

src/credentials/GroupDataProviderImpl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ class GroupDataProviderImpl : public GroupDataProvider
161161
mProvider(provider)
162162

163163
{
164-
Initialize(encryptionKey, hash, privacyKey);
164+
TEMPORARY_RETURN_IGNORED Initialize(encryptionKey, hash, privacyKey);
165165
}
166166

167-
void Initialize(const Crypto::Symmetric128BitsKeyByteArray & encryptionKey, uint16_t hash,
168-
const Crypto::Symmetric128BitsKeyByteArray & privacyKey)
167+
CHIP_ERROR Initialize(const Crypto::Symmetric128BitsKeyByteArray & encryptionKey, uint16_t hash,
168+
const Crypto::Symmetric128BitsKeyByteArray & privacyKey)
169169
{
170170
ReleaseKeys();
171171
mKeyHash = hash;
@@ -176,8 +176,8 @@ class GroupDataProviderImpl : public GroupDataProvider
176176
// like more work, so let's use the transitional code below for now.
177177

178178
Crypto::SessionKeystore * keystore = mProvider.GetSessionKeystore();
179-
keystore->CreateKey(encryptionKey, mEncryptionKey);
180-
keystore->CreateKey(privacyKey, mPrivacyKey);
179+
ReturnErrorOnFailure(keystore->CreateKey(encryptionKey, mEncryptionKey));
180+
return keystore->CreateKey(privacyKey, mPrivacyKey);
181181
}
182182

183183
void ReleaseKeys()

0 commit comments

Comments
 (0)