diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 3419ec227b956d..fe78374f8f494c 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -166,9 +166,9 @@ void CHIPCommand::MaybeTearDownStack() // since the CHIP thread and event queue have been stopped, preventing any thread // races. // - for (auto it = mCommissioners.begin(); it != mCommissioners.end(); it++) + for (auto & commissioner : mCommissioners) { - ShutdownCommissioner(it->first); + ShutdownCommissioner(commissioner.first); } StopTracing(); diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 6717bcbbc03216..59d678158ed073 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -42,9 +42,9 @@ bool Command::InitArguments(int argc, char ** argv) size_t argvExtraArgsCount = (size_t) argc; size_t mandatoryArgsCount = 0; size_t optionalArgsCount = 0; - for (size_t i = 0; i < mArgs.size(); i++) + for (auto & arg : mArgs) { - if (mArgs[i].isOptional()) + if (arg.isOptional()) { optionalArgsCount++; } @@ -877,9 +877,8 @@ void ResetOptionalArg(const Argument & arg) void Command::ResetArguments() { - for (size_t i = 0; i < mArgs.size(); i++) + for (const auto & arg : mArgs) { - const Argument arg = mArgs[i]; const ArgumentType type = arg.type; if (arg.isOptional()) { diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 3251d924c7c7b0..8f2b147a6159af 100644 --- a/src/app/BufferedReadCallback.cpp +++ b/src/app/BufferedReadCallback.cpp @@ -65,9 +65,9 @@ CHIP_ERROR BufferedReadCallback::GenerateListTLV(TLV::ScopedBufferTLVReader & aR // To avoid that, a single contiguous buffer is the best likely approach for now. // uint32_t totalBufSize = 0; - for (size_t i = 0; i < mBufferedList.size(); i++) + for (const auto & packetBuffer : mBufferedList) { - totalBufSize += mBufferedList[i]->TotalLength(); + totalBufSize += packetBuffer->TotalLength(); } // diff --git a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp index 0d7add50c721ae..64607c32032cf9 100644 --- a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp +++ b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp @@ -58,9 +58,9 @@ bool IsTestEventTriggerEnabled() bool IsByteSpanAllZeros(const ByteSpan & byteSpan) { - for (auto * it = byteSpan.begin(); it != byteSpan.end(); ++it) + for (unsigned char it : byteSpan) { - if (*it != 0) + if (it != 0) { return false; } diff --git a/src/app/tests/TestAttributeValueEncoder.cpp b/src/app/tests/TestAttributeValueEncoder.cpp index e063e0e888ac0e..a75c692428f963 100644 --- a/src/app/tests/TestAttributeValueEncoder.cpp +++ b/src/app/tests/TestAttributeValueEncoder.cpp @@ -261,9 +261,9 @@ void TestEncodeFabricScoped(nlTestSuite * aSuite, void * aContext) // We tried to encode three items, however, the encoder should only put the item with matching fabric index into the final list. CHIP_ERROR err = test.encoder.EncodeList([items](const auto & encoder) -> CHIP_ERROR { - for (size_t i = 0; i < 3; i++) + for (const auto & item : items) { - ReturnErrorOnFailure(encoder.Encode(items[i])); + ReturnErrorOnFailure(encoder.Encode(item)); } return CHIP_NO_ERROR; }); diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp index 7f5f091a253252..990bc0c8fa55d4 100644 --- a/src/app/tests/TestPendingNotificationMap.cpp +++ b/src/app/tests/TestPendingNotificationMap.cpp @@ -80,10 +80,10 @@ void TestAddRemove(nlTestSuite * aSuite, void * aContext) pendingMap.RemoveAllEntriesForNode(chip::ScopedNodeId()); uint8_t expectedEntryIndecies[] = { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; iter = pendingMap.begin(); - for (size_t i = 0; i < sizeof(expectedEntryIndecies); i++) + for (uint8_t ch : expectedEntryIndecies) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == expectedEntryIndecies[i]); + NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == ch); ++iter; } NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 9a27ba771b9497..b52d0ffec702cc 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -1225,11 +1225,11 @@ void TestReadInteraction::TestSetDirtyBetweenChunks(nlTestSuite * apSuite, void NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); chip::app::AttributePathParams attributePathParams[2]; - for (int i = 0; i < 2; i++) + for (auto & attributePathParam : attributePathParams) { - attributePathParams[i].mEndpointId = Test::kMockEndpoint3; - attributePathParams[i].mClusterId = Test::MockClusterId(2); - attributePathParams[i].mAttributeId = Test::MockAttributeId(4); + attributePathParam.mEndpointId = Test::kMockEndpoint3; + attributePathParam.mClusterId = Test::MockClusterId(2); + attributePathParam.mAttributeId = Test::MockAttributeId(4); } ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice()); @@ -2213,10 +2213,10 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte // // Allocate a number of clients // - for (int i = 0; i < 4; i++) + for (auto & client : pClients) { - pClients[i] = Platform::New(engine, &ctx.GetExchangeManager(), delegate, - chip::app::ReadClient::InteractionType::Subscribe); + client = Platform::New(engine, &ctx.GetExchangeManager(), delegate, + chip::app::ReadClient::InteractionType::Subscribe); } // diff --git a/src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp b/src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp index 21b39496316d3b..7aac171f20b128 100644 --- a/src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp +++ b/src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp @@ -39,9 +39,8 @@ void PICSBooleanExpressionParser::Tokenize(std::string & expression, std::vector std::string s; - for (size_t i = 0; i < expression.size(); i++) + for (char c : expression) { - char c = expression[i]; switch (c) { case ' ': diff --git a/src/ble/BleLayer.cpp b/src/ble/BleLayer.cpp index 881ba991cc3036..3b2db861743de8 100644 --- a/src/ble/BleLayer.cpp +++ b/src/ble/BleLayer.cpp @@ -203,9 +203,11 @@ CHIP_ERROR BleTransportCapabilitiesRequestMessage::Decode(const PacketBufferHand VerifyOrReturnError(CAPABILITIES_MSG_CHECK_BYTE_1 == chip::Encoding::Read8(p), BLE_ERROR_INVALID_MESSAGE); VerifyOrReturnError(CAPABILITIES_MSG_CHECK_BYTE_2 == chip::Encoding::Read8(p), BLE_ERROR_INVALID_MESSAGE); - for (size_t i = 0; i < kCapabilitiesRequestSupportedVersionsLength; i++) + static_assert(kCapabilitiesRequestSupportedVersionsLength == sizeof(msg.mSupportedProtocolVersions), + "Expected capability sizes and storage must match"); + for (unsigned char & version : msg.mSupportedProtocolVersions) { - msg.mSupportedProtocolVersions[i] = chip::Encoding::Read8(p); + version = chip::Encoding::Read8(p); } msg.mMtu = chip::Encoding::LittleEndian::Read16(p); diff --git a/src/controller/tests/TestWriteChunking.cpp b/src/controller/tests/TestWriteChunking.cpp index bd27e649bd79d1..726e73fe33eb19 100644 --- a/src/controller/tests/TestWriteChunking.cpp +++ b/src/controller/tests/TestWriteChunking.cpp @@ -289,9 +289,9 @@ void TestWriteChunking::TestBadChunking(nlTestSuite * apSuite, void * apContext) app::WriteClient writeClient(&ctx.GetExchangeManager(), &writeCallback, Optional::Missing()); ByteSpan list[kTestListLength]; - for (uint8_t j = 0; j < kTestListLength; j++) + for (auto & item : list) { - list[j] = ByteSpan(sByteSpanData, static_cast(i)); + item = ByteSpan(sByteSpanData, static_cast(i)); } err = writeClient.EncodeAttribute(attributePath, app::DataModel::List(list, kTestListLength)); diff --git a/src/controller/tests/data_model/TestRead.cpp b/src/controller/tests/data_model/TestRead.cpp index d9f3a0725b16bb..5c1677a50b8cc4 100644 --- a/src/controller/tests/data_model/TestRead.cpp +++ b/src/controller/tests/data_model/TestRead.cpp @@ -427,11 +427,11 @@ void TestReadInteraction::TestReadSubscribeAttributeResponseWithCache(nlTestSuit chip::app::ClusterStateCache cache(delegate); chip::app::EventPathParams eventPathParams[100]; - for (uint32_t index = 0; index < 100; index++) + for (auto & eventPathParam : eventPathParams) { - eventPathParams[index].mEndpointId = Test::kMockEndpoint3; - eventPathParams[index].mClusterId = Test::MockClusterId(2); - eventPathParams[index].mEventId = 0; + eventPathParam.mEndpointId = Test::kMockEndpoint3; + eventPathParam.mClusterId = Test::MockClusterId(2); + eventPathParam.mEventId = 0; } chip::app::ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice()); diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp index e5167d05dea768..c2a4ba424af2a7 100644 --- a/src/credentials/CHIPCert.cpp +++ b/src/credentials/CHIPCert.cpp @@ -616,9 +616,9 @@ ChipDN::~ChipDN() {} void ChipDN::Clear() { - for (uint8_t i = 0; i < CHIP_CONFIG_CERT_MAX_RDN_ATTRIBUTES; i++) + for (auto & dn : rdn) { - rdn[i].Clear(); + dn.Clear(); } } diff --git a/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp b/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp index 70684157014515..a57a45cc6e36a9 100644 --- a/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp +++ b/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp @@ -645,11 +645,11 @@ CHIP_ERROR CsaCdKeysTrustStore::AddTrustedKey(const ByteSpan & derCertBytes) CHIP_ERROR CsaCdKeysTrustStore::LookupVerifyingKey(const ByteSpan & kid, Crypto::P256PublicKey & outPubKey) const { // First, search for the well known keys - for (size_t keyIdx = 0; keyIdx < gCdSigningKeys.size(); keyIdx++) + for (auto & cdSigningKey : gCdSigningKeys) { - if (kid.data_equal(gCdSigningKeys[keyIdx].mKid)) + if (kid.data_equal(cdSigningKey.mKid)) { - outPubKey = gCdSigningKeys[keyIdx].mPubkey; + outPubKey = cdSigningKey.mPubkey; return CHIP_NO_ERROR; } } diff --git a/src/credentials/tests/TestCertificationDeclaration.cpp b/src/credentials/tests/TestCertificationDeclaration.cpp index 262ac5fe3e2461..7150db4a44eacf 100644 --- a/src/credentials/tests/TestCertificationDeclaration.cpp +++ b/src/credentials/tests/TestCertificationDeclaration.cpp @@ -262,14 +262,10 @@ static constexpr TestCase sTestCases[] = { ByteSpan(sTestCMS_CDContent02), ByteSpan(sTestCMS_SignedMessage02) }, }; -static constexpr size_t sNumTestCases = ArraySize(sTestCases); - static void TestCD_EncodeDecode(nlTestSuite * inSuite, void * inContext) { - for (size_t i = 0; i < sNumTestCases; i++) + for (const auto & testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; - uint8_t encodedCertElemBuf[kCertificationElements_TLVEncodedMaxLength]; MutableByteSpan encodedCDPayload(encodedCertElemBuf); @@ -379,10 +375,8 @@ static void TestCD_CMSSignAndVerify(nlTestSuite * inSuite, void * inContext) static void TestCD_CMSVerifyAndExtract(nlTestSuite * inSuite, void * inContext) { - for (size_t i = 0; i < sNumTestCases; i++) + for (const auto & testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; - // Verify using signer P256PublicKey ByteSpan cdContentOut; NL_TEST_ASSERT(inSuite, @@ -412,10 +406,8 @@ static void TestCD_CMSVerifyAndExtract(nlTestSuite * inSuite, void * inContext) static void TestCD_CertificationElementsDecoder(nlTestSuite * inSuite, void * inContext) { - for (size_t i = 0; i < sNumTestCases; i++) + for (const auto & testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; - uint8_t encodedCertElemBuf[kCertificationElements_TLVEncodedMaxLength]; MutableByteSpan encodedCDPayload(encodedCertElemBuf); diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index 3725f00acd1a6b..d3610b5f4ab49e 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -428,22 +428,18 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext) { TestCert::kNode01_01, sGenTBSHashFlag, sNullLoadFlag } } }, }; // clang-format on - static const size_t sNumValidationTestCases = ArraySize(sValidationTestCases); - for (unsigned i = 0; i < sNumValidationTestCases; i++) + for (const auto & testCase : sValidationTestCases) { const ChipCertificateData * resultCert = nullptr; - const ValidationTestCase & testCase = sValidationTestCases[i]; - - err = certSet.Init(kMaxCertsPerTestCase); + err = certSet.Init(kMaxCertsPerTestCase); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - for (size_t i2 = 0; i2 < kMaxCertsPerTestCase; i2++) + for (auto inputCert : testCase.InputCerts) { - if (testCase.InputCerts[i2].Type != TestCert::kNone) + if (inputCert.Type != TestCert::kNone) { - err = LoadTestCert(certSet, testCase.InputCerts[i2].Type, testCase.InputCerts[i2].LoadFlags, - testCase.InputCerts[i2].DecodeFlags); + err = LoadTestCert(certSet, inputCert.Type, inputCert.LoadFlags, inputCert.DecodeFlags); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } } @@ -1137,11 +1133,8 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, kCertType_Node }, }; // clang-format on - static const size_t sNumTestCases = ArraySize(sTestCases); - - for (unsigned i = 0; i < sNumTestCases; i++) + for (const auto & testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; uint8_t certType; err = certSet.Init(1); @@ -1186,11 +1179,8 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, 0xDEDEDEDE00020002 }, }; // clang-format on - static const size_t sNumTestCases = ArraySize(sTestCases); - - for (unsigned i = 0; i < sNumTestCases; i++) + for (const auto & testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; uint64_t chipId; err = certSet.Init(certData, 1); diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 721fb7dc02abb3..739215b34e5f4c 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -204,8 +204,6 @@ const AesCtrTestEntry theAesCtrTestVector[] = { } }; -constexpr size_t kAesCtrTestVectorSize = sizeof(theAesCtrTestVector) / sizeof(theAesCtrTestVector[0]); - constexpr size_t KEY_LENGTH = Crypto::kAES_CCM128_Key_Length; constexpr size_t NONCE_LENGTH = Crypto::kAES_CCM128_Nonce_Length; @@ -249,14 +247,13 @@ static void TestAES_CTR_128CryptTestVectors(nlTestSuite * inSuite, void * inCont { HeapChecker heapChecker(inSuite); int numOfTestsRan = 0; - for (size_t vectorIndex = 0; vectorIndex < kAesCtrTestVectorSize; vectorIndex++) + for (const auto & vector : theAesCtrTestVector) { - const AesCtrTestEntry * vector = &theAesCtrTestVector[vectorIndex]; - if (vector->plaintextLen > 0) + if (vector.plaintextLen > 0) { numOfTestsRan++; - TestAES_CTR_128_Encrypt(inSuite, vector); - TestAES_CTR_128_Decrypt(inSuite, vector); + TestAES_CTR_128_Encrypt(inSuite, &vector); + TestAES_CTR_128_Decrypt(inSuite, &vector); } } NL_TEST_ASSERT(inSuite, numOfTestsRan > 0); diff --git a/src/crypto/tests/TestGroupOperationalCredentials.cpp b/src/crypto/tests/TestGroupOperationalCredentials.cpp index b7493cc7d853a0..1f0eeb5f17e503 100644 --- a/src/crypto/tests/TestGroupOperationalCredentials.cpp +++ b/src/crypto/tests/TestGroupOperationalCredentials.cpp @@ -80,22 +80,19 @@ struct GroupKeySetTestEntry theGroupKeySetTestVector[] = { }, }; -const uint16_t theGroupKeySetTestVectorLength = sizeof(theGroupKeySetTestVector) / sizeof(theGroupKeySetTestVector[0]); - void TestDeriveGroupOperationalCredentials(nlTestSuite * apSuite, void * apContext) { GroupOperationalCredentials opCreds; - for (unsigned i = 0; i < theGroupKeySetTestVectorLength; i++) + for (const auto & testVector : theGroupKeySetTestVector) { - const ByteSpan epochKey(theGroupKeySetTestVector[i].epochKey, KEY_LENGTH); + const ByteSpan epochKey(testVector.epochKey, KEY_LENGTH); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == Crypto::DeriveGroupOperationalCredentials(epochKey, kCompressedFabricId1, opCreds)); - NL_TEST_ASSERT(apSuite, opCreds.hash == theGroupKeySetTestVector[i].groupKeys->hash); - NL_TEST_ASSERT(apSuite, - 0 == memcmp(opCreds.encryption_key, theGroupKeySetTestVector[i].groupKeys->encryption_key, KEY_LENGTH)); - NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.privacy_key, theGroupKeySetTestVector[i].groupKeys->privacy_key, KEY_LENGTH)); + NL_TEST_ASSERT(apSuite, opCreds.hash == testVector.groupKeys->hash); + NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.encryption_key, testVector.groupKeys->encryption_key, KEY_LENGTH)); + NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.privacy_key, testVector.groupKeys->privacy_key, KEY_LENGTH)); } } diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 0bc8000138addf..6a7d856aa6e3b7 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -292,9 +292,9 @@ void Resolver::ReArmTimer() System::Clock::Timestamp now = mTimeSource.GetMonotonicTimestamp(); System::Clock::Timeout nextTimeout = kInvalidTimeout; - for (auto it = mActiveLookups.begin(); it != mActiveLookups.end(); it++) + for (auto & activeLookup : mActiveLookups) { - System::Clock::Timeout timeout = it->NextEventTimeout(now); + System::Clock::Timeout timeout = activeLookup.NextEventTimeout(now); if (timeout < nextTimeout) { diff --git a/src/lib/asn1/ASN1OID.cpp b/src/lib/asn1/ASN1OID.cpp index 106e43c0e803df..4734a4aa7ad527 100644 --- a/src/lib/asn1/ASN1OID.cpp +++ b/src/lib/asn1/ASN1OID.cpp @@ -46,11 +46,11 @@ DLL_EXPORT OID ParseObjectID(const uint8_t * encodedOID, uint16_t encodedOIDLen) return kOID_NotSpecified; } - for (uint32_t i = 0; i < sOIDTableSize; i++) + for (const auto & tableEntry : sOIDTable) { - if (encodedOIDLen == sOIDTable[i].EncodedOIDLen && memcmp(encodedOID, sOIDTable[i].EncodedOID, encodedOIDLen) == 0) + if (encodedOIDLen == tableEntry.EncodedOIDLen && memcmp(encodedOID, tableEntry.EncodedOID, encodedOIDLen) == 0) { - return sOIDTable[i].EnumVal; + return tableEntry.EnumVal; } } @@ -59,12 +59,12 @@ DLL_EXPORT OID ParseObjectID(const uint8_t * encodedOID, uint16_t encodedOIDLen) bool GetEncodedObjectID(OID oid, const uint8_t *& encodedOID, uint16_t & encodedOIDLen) { - for (uint32_t i = 0; i < sOIDTableSize; i++) + for (const auto & tableEntry : sOIDTable) { - if (oid == sOIDTable[i].EnumVal) + if (oid == tableEntry.EnumVal) { - encodedOID = sOIDTable[i].EncodedOID; - encodedOIDLen = sOIDTable[i].EncodedOIDLen; + encodedOID = tableEntry.EncodedOID; + encodedOIDLen = tableEntry.EncodedOIDLen; return true; } } @@ -95,11 +95,11 @@ const char * GetOIDName(OID oid) { return "NotSpecified"; } - for (uint32_t i = 0; i < sOIDTableSize; i++) + for (const auto & tableEntry : sOIDNameTable) { - if (oid == sOIDNameTable[i].EnumVal) + if (oid == tableEntry.EnumVal) { - return sOIDNameTable[i].Name; + return tableEntry.Name; } } return "Unknown"; diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp index 7c6220baa4b8dd..ef530355c02ed3 100644 --- a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp +++ b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp @@ -55,11 +55,11 @@ CHIP_ERROR ResponseSender::AddQueryResponder(QueryResponderBase * queryResponder // If already existing or we find a free slot, just use it // Note that dynamic memory implementations are never expected to be nullptr // - for (auto it = mResponders.begin(); it != mResponders.end(); it++) + for (auto & responder : mResponders) { - if (*it == nullptr || *it == queryResponder) + if (responder == nullptr || responder == queryResponder) { - *it = queryResponder; + responder = queryResponder; return CHIP_NO_ERROR; } } @@ -90,9 +90,9 @@ CHIP_ERROR ResponseSender::RemoveQueryResponder(QueryResponderBase * queryRespon bool ResponseSender::HasQueryResponders() const { - for (auto it = mResponders.begin(); it != mResponders.end(); it++) + for (auto responder : mResponders) { - if (*it != nullptr) + if (responder != nullptr) { return true; } @@ -108,12 +108,12 @@ CHIP_ERROR ResponseSender::Respond(uint32_t messageId, const QueryData & query, // Responder has a stateful 'additional replies required' that is used within the response // loop. 'no additionals required' is set at the start and additionals are marked as the query // reply is built. - for (auto it = mResponders.begin(); it != mResponders.end(); it++) + for (auto & responder : mResponders) { { - if (*it != nullptr) + if (responder != nullptr) { - (*it)->ResetAdditionals(); + responder->ResetAdditionals(); } } } @@ -135,18 +135,18 @@ CHIP_ERROR ResponseSender::Respond(uint32_t messageId, const QueryData & query, // broadcasts on one interface to throttle broadcasts on another interface. responseFilter.SetIncludeOnlyMulticastBeforeMS(kTimeNow - chip::System::Clock::Seconds32(1)); } - for (auto responder = mResponders.begin(); responder != mResponders.end(); responder++) + for (auto & responder : mResponders) { - if (*responder == nullptr) + if (responder == nullptr) { continue; } - for (auto it = (*responder)->begin(&responseFilter); it != (*responder)->end(); it++) + for (auto it = responder->begin(&responseFilter); it != responder->end(); it++) { it->responder->AddAllResponses(querySource, this, configuration); ReturnErrorOnFailure(mSendState.GetError()); - (*responder)->MarkAdditionalRepliesFor(it); + responder->MarkAdditionalRepliesFor(it); if (!mSendState.SendUnicast()) { @@ -168,13 +168,13 @@ CHIP_ERROR ResponseSender::Respond(uint32_t messageId, const QueryData & query, responseFilter .SetReplyFilter(&queryReplyFilter) // .SetIncludeAdditionalRepliesOnly(true); - for (auto responder = mResponders.begin(); responder != mResponders.end(); responder++) + for (auto & responder : mResponders) { - if (*responder == nullptr) + if (responder == nullptr) { continue; } - for (auto it = (*responder)->begin(&responseFilter); it != (*responder)->end(); it++) + for (auto it = responder->begin(&responseFilter); it != responder->end(); it++) { it->responder->AddAllResponses(querySource, this, configuration); ReturnErrorOnFailure(mSendState.GetError()); diff --git a/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp b/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp index 1cd8b68cc71dd4..c03bb32990506f 100644 --- a/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp +++ b/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp @@ -131,11 +131,11 @@ void RecordWriter::RememberWrittenQnameOffset(size_t offset) return; } - for (size_t i = 0; i < kMaxCachedReferences; i++) + for (unsigned short & previousName : mPreviousQNames) { - if (mPreviousQNames[i] == kInvalidOffset) + if (previousName == kInvalidOffset) { - mPreviousQNames[i] = offset; + previousName = offset; return; } } diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 53bf730763879f..f35ebf3183ae49 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -293,9 +293,9 @@ bool NodeDataIsEmpty(const DiscoveredNodeData & node) { return false; } - for (size_t i = 0; i < sizeof(CommissionNodeData::rotatingId); ++i) + for (uint8_t id : node.commissionData.rotatingId) { - if (node.commissionData.rotatingId[i] != 0) + if (id != 0) { return false; } diff --git a/src/lib/support/tests/TestIntrusiveList.cpp b/src/lib/support/tests/TestIntrusiveList.cpp index ddb121b1262355..c961a643ed0d1f 100644 --- a/src/lib/support/tests/TestIntrusiveList.cpp +++ b/src/lib/support/tests/TestIntrusiveList.cpp @@ -52,28 +52,28 @@ void TestIntrusiveListRandom(nlTestSuite * inSuite, void * inContext) fun(l1p, l2p); }; - for (int i = 0; i < 100; ++i) + for (auto & n : node) { switch (std::rand() % 5) { case 0: // PushFront - l1.PushFront(&node[i]); - l2.push_front(&node[i]); + l1.PushFront(&n); + l2.push_front(&n); break; case 1: // PushBack - l1.PushBack(&node[i]); - l2.push_back(&node[i]); + l1.PushBack(&n); + l2.push_back(&n); break; case 2: // InsertBefore op([&](auto & l1p, auto & l2p) { - l1.InsertBefore(l1p, &node[i]); - l2.insert(l2p, &node[i]); + l1.InsertBefore(l1p, &n); + l2.insert(l2p, &n); }); break; case 3: // InsertAfter op([&](auto & l1p, auto & l2p) { - l1.InsertAfter(l1p, &node[i]); - l2.insert(++l2p, &node[i]); + l1.InsertAfter(l1p, &n); + l2.insert(++l2p, &n); }); break; case 4: // Remove diff --git a/src/lib/support/tests/TestPool.cpp b/src/lib/support/tests/TestPool.cpp index 4a9f7d808062d1..befeef1a51397a 100644 --- a/src/lib/support/tests/TestPool.cpp +++ b/src/lib/support/tests/TestPool.cpp @@ -180,9 +180,9 @@ void TestCreateReleaseStruct(nlTestSuite * inSuite, void * inContext) } // Verify that ReleaseAll() calls the destructors. - for (size_t i = 0; i < kSize; ++i) + for (auto & obj : objs2) { - objs2[i] = pool.CreateObject(objs1); + obj = pool.CreateObject(objs1); } NL_TEST_ASSERT(inSuite, objs1.size() == kSize); NL_TEST_ASSERT(inSuite, pool.Allocated() == kSize); diff --git a/src/lib/support/tests/TestPrivateHeap.cpp b/src/lib/support/tests/TestPrivateHeap.cpp index 85bdd9109290b3..09f2ae7f7d56d3 100644 --- a/src/lib/support/tests/TestPrivateHeap.cpp +++ b/src/lib/support/tests/TestPrivateHeap.cpp @@ -215,11 +215,11 @@ void ForwardFreeAndRealloc(nlTestSuite * inSuite, void * inContext) PrivateHeapAllocator<(2 * kNumBlocks + 1) * kBlockHeaderSize> allocator; void * ptrs[kNumBlocks]; - for (int i = 0; i < kNumBlocks; ++i) + for (auto & ptr : ptrs) { - ptrs[i] = allocator.HeapAlloc(kBlockHeaderSize); - NL_TEST_ASSERT(inSuite, nullptr != ptrs[i]); - memset(ptrs[i], 0xab, kBlockHeaderSize); + ptr = allocator.HeapAlloc(kBlockHeaderSize); + NL_TEST_ASSERT(inSuite, nullptr != ptr); + memset(ptr, 0xab, kBlockHeaderSize); } // heap looks like: @@ -243,11 +243,11 @@ void BackwardFreeAndRealloc(nlTestSuite * inSuite, void * inContext) PrivateHeapAllocator<(2 * kNumBlocks + 1) * kBlockHeaderSize> allocator; void * ptrs[kNumBlocks]; - for (int i = 0; i < kNumBlocks; ++i) + for (auto & ptr : ptrs) { - ptrs[i] = allocator.HeapAlloc(kBlockHeaderSize); - NL_TEST_ASSERT(inSuite, nullptr != ptrs[i]); - memset(ptrs[i], 0xab, kBlockHeaderSize); + ptr = allocator.HeapAlloc(kBlockHeaderSize); + NL_TEST_ASSERT(inSuite, nullptr != ptr); + memset(ptr, 0xab, kBlockHeaderSize); } // heap looks like: diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index e4e9f609d2b275..eb8661550376df 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -266,9 +266,6 @@ struct BackoffComplianceTestVector theBackoffComplianceTestVector[] = { }, }; -const unsigned theBackoffComplianceTestVectorLength = - sizeof(theBackoffComplianceTestVector) / sizeof(struct BackoffComplianceTestVector); - void CheckAddClearRetrans(nlTestSuite * inSuite, void * inContext) { TestContext & ctx = *reinterpret_cast(inContext); @@ -1651,15 +1648,14 @@ void CheckGetBackoff(nlTestSuite * inSuite, void * inContext) // Run 3x iterations to thoroughly test random jitter always results in backoff within bounds. for (uint32_t j = 0; j < 3; j++) { - for (uint32_t i = 0; i < theBackoffComplianceTestVectorLength; i++) + for (const auto & test : theBackoffComplianceTestVector) { - struct BackoffComplianceTestVector * test = &theBackoffComplianceTestVector[i]; - System::Clock::Timeout backoff = ReliableMessageMgr::GetBackoff(test->backoffBase, test->sendCount); - ChipLogProgress(Test, "Backoff base %" PRIu32 " # %d: %" PRIu32, test->backoffBase.count(), test->sendCount, + System::Clock::Timeout backoff = ReliableMessageMgr::GetBackoff(test.backoffBase, test.sendCount); + ChipLogProgress(Test, "Backoff base %" PRIu32 " # %d: %" PRIu32, test.backoffBase.count(), test.sendCount, backoff.count()); - NL_TEST_ASSERT(inSuite, backoff >= test->backoffMin); - NL_TEST_ASSERT(inSuite, backoff <= test->backoffMax); + NL_TEST_ASSERT(inSuite, backoff >= test.backoffMin); + NL_TEST_ASSERT(inSuite, backoff <= test.backoffMax); } } } diff --git a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp index 21664e1226787f..c08a0a3bf9e6af 100644 --- a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp +++ b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp @@ -295,27 +295,24 @@ void TestDelete(nlTestSuite * inSuite, void * inContext) } // Fill storage. - for (size_t i = 0; i < sizeof(vectors) / sizeof(vectors[0]); ++i) + for (auto & vector : vectors) { NL_TEST_ASSERT(inSuite, - sessionStorage.Save(vectors[i].node, vectors[i].resumptionId, sharedSecret, chip::CATValues{}) == - CHIP_NO_ERROR); + sessionStorage.Save(vector.node, vector.resumptionId, sharedSecret, chip::CATValues{}) == CHIP_NO_ERROR); } // Delete values in turn from storage and verify they are removed. - for (size_t i = 0; i < ArraySize(vectors); ++i) + for (auto & vector : vectors) { chip::ScopedNodeId outNode; chip::SessionResumptionStorage::ResumptionIdStorage outResumptionId; chip::Crypto::P256ECDHDerivedSecret outSharedSecret; chip::CATValues outCats; - NL_TEST_ASSERT(inSuite, sessionStorage.Delete(vectors[i].node) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, sessionStorage.Delete(vector.node) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, - sessionStorage.FindByScopedNodeId(vectors[i].node, outResumptionId, outSharedSecret, outCats) != - CHIP_NO_ERROR); + sessionStorage.FindByScopedNodeId(vector.node, outResumptionId, outSharedSecret, outCats) != CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, - sessionStorage.FindByResumptionId(vectors[i].resumptionId, outNode, outSharedSecret, outCats) != - CHIP_NO_ERROR); + sessionStorage.FindByResumptionId(vector.resumptionId, outNode, outSharedSecret, outCats) != CHIP_NO_ERROR); } // Verify no state or link table persistent storage entries were leaked. diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index 92cedf5f3b9427..cc462769d7f9dd 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -271,9 +271,9 @@ int PacketBufferTest::TerminateTest(TestContext * context) { const bool context_ok = (context == mContext); // Clear the configurations' bufffer handles. - for (size_t i = 0; i < configurations.size(); ++i) + for (auto & configuration : configurations) { - configurations[i].handle = nullptr; + configuration.handle = nullptr; } const bool handles_ok = ResetHandles(); return (context_ok && handles_ok) ? SUCCESS : FAILURE; @@ -1817,9 +1817,9 @@ void PacketBufferTest::CheckHandleCloneData(nlTestSuite * inSuite, void * inCont NL_TEST_ASSERT(inSuite, test->mContext == theContext); uint8_t lPayload[2 * PacketBuffer::kMaxSizeWithoutReserve]; - for (size_t i = 0; i < sizeof(lPayload); ++i) + for (uint8_t & payload : lPayload) { - lPayload[i] = static_cast(random()); + payload = static_cast(random()); } for (auto & config_1 : test->configurations) diff --git a/src/system/tests/TestSystemTimer.cpp b/src/system/tests/TestSystemTimer.cpp index f88cf12f552333..1ad153369a13c2 100644 --- a/src/system/tests/TestSystemTimer.cpp +++ b/src/system/tests/TestSystemTimer.cpp @@ -341,18 +341,18 @@ int gCallbackProcessed[kCancelTimerCount]; /// Validates that gCallbackProcessed has valid values (0 or 1) void ValidateExecutedTimerCounts(nlTestSuite * suite) { - for (unsigned i = 0; i < kCancelTimerCount; i++) + for (int processed : gCallbackProcessed) { - NL_TEST_ASSERT(suite, (gCallbackProcessed[i] == 0) || (gCallbackProcessed[i] == 1)); + NL_TEST_ASSERT(suite, (processed == 0) || (processed == 1)); } } unsigned ExecutedTimerCount() { unsigned count = 0; - for (unsigned i = 0; i < kCancelTimerCount; i++) + for (int processed : gCallbackProcessed) { - if (gCallbackProcessed[i] != 0) + if (processed != 0) { count++; } diff --git a/src/transport/raw/MessageHeader.h b/src/transport/raw/MessageHeader.h index 5589647bd9ebc9..b811cb17797b34 100644 --- a/src/transport/raw/MessageHeader.h +++ b/src/transport/raw/MessageHeader.h @@ -661,7 +661,7 @@ class MessageAuthenticationCode const uint8_t * GetTag() const { return &mTag[0]; } /** Set the message auth tag for this header. */ - MessageAuthenticationCode & SetTag(PacketHeader * header, uint8_t * tag, size_t len) + MessageAuthenticationCode & SetTag(PacketHeader * header, const uint8_t * tag, size_t len) { const size_t tagLen = chip::Crypto::CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES; if (tagLen > 0 && tagLen <= kMaxTagLen && len == tagLen) diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index 1ad9b7b1e03d64..dc15dc894b0f49 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -373,52 +373,45 @@ struct SpecComplianceTestVector theSpecComplianceTestVector[] = { }, }; -const unsigned theSpecComplianceTestVectorLength = sizeof(theSpecComplianceTestVector) / sizeof(struct SpecComplianceTestVector); - void TestSpecComplianceEncode(nlTestSuite * inSuite, void * inContext) { - struct SpecComplianceTestVector * testEntry; uint8_t buffer[MAX_FIXED_HEADER_SIZE]; uint16_t encodeSize; - for (unsigned i = 0; i < theSpecComplianceTestVectorLength; i++) + for (const auto & testEntry : theSpecComplianceTestVector) { PacketHeader packetHeader; - testEntry = &theSpecComplianceTestVector[i]; - packetHeader.SetMessageFlags(testEntry->messageFlags); - packetHeader.SetSecurityFlags(testEntry->securityFlags); - packetHeader.SetSessionId(testEntry->sessionId); - packetHeader.SetMessageCounter(testEntry->messageCounter); + packetHeader.SetMessageFlags(testEntry.messageFlags); + packetHeader.SetSecurityFlags(testEntry.securityFlags); + packetHeader.SetSessionId(testEntry.sessionId); + packetHeader.SetMessageCounter(testEntry.messageCounter); - if (testEntry->groupId >= 0) + if (testEntry.groupId >= 0) { - packetHeader.SetDestinationGroupId(static_cast(testEntry->groupId)); + packetHeader.SetDestinationGroupId(static_cast(testEntry.groupId)); } NL_TEST_ASSERT(inSuite, packetHeader.Encode(buffer, sizeof(buffer), &encodeSize) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, encodeSize == testEntry->size); - NL_TEST_ASSERT(inSuite, memcmp(buffer, testEntry->encoded, encodeSize) == 0); + NL_TEST_ASSERT(inSuite, encodeSize == testEntry.size); + NL_TEST_ASSERT(inSuite, memcmp(buffer, testEntry.encoded, encodeSize) == 0); } } void TestSpecComplianceDecode(nlTestSuite * inSuite, void * inContext) { - struct SpecComplianceTestVector * testEntry; PacketHeader packetHeader; uint16_t decodeSize; - for (unsigned i = 0; i < theSpecComplianceTestVectorLength; i++) + for (const auto & testEntry : theSpecComplianceTestVector) { - testEntry = &theSpecComplianceTestVector[i]; - - NL_TEST_ASSERT(inSuite, packetHeader.Decode(testEntry->encoded, testEntry->size, &decodeSize) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, decodeSize == testEntry->size); - NL_TEST_ASSERT(inSuite, packetHeader.GetMessageFlags() == testEntry->messageFlags); - NL_TEST_ASSERT(inSuite, packetHeader.GetSecurityFlags() == testEntry->securityFlags); - NL_TEST_ASSERT(inSuite, packetHeader.GetSessionId() == testEntry->sessionId); - NL_TEST_ASSERT(inSuite, packetHeader.GetMessageCounter() == testEntry->messageCounter); - NL_TEST_ASSERT(inSuite, packetHeader.IsEncrypted() == testEntry->isSecure); + NL_TEST_ASSERT(inSuite, packetHeader.Decode(testEntry.encoded, testEntry.size, &decodeSize) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, decodeSize == testEntry.size); + NL_TEST_ASSERT(inSuite, packetHeader.GetMessageFlags() == testEntry.messageFlags); + NL_TEST_ASSERT(inSuite, packetHeader.GetSecurityFlags() == testEntry.securityFlags); + NL_TEST_ASSERT(inSuite, packetHeader.GetSessionId() == testEntry.sessionId); + NL_TEST_ASSERT(inSuite, packetHeader.GetMessageCounter() == testEntry.messageCounter); + NL_TEST_ASSERT(inSuite, packetHeader.IsEncrypted() == testEntry.isSecure); } } @@ -517,28 +510,23 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { }, }; -const unsigned theTestVectorMsgExtensionsLength = sizeof(theTestVectorMsgExtensions) / sizeof(struct TestVectorMsgExtensions); - void TestMsgExtensionsDecode(nlTestSuite * inSuite, void * inContext) { - struct TestVectorMsgExtensions * testEntry; PacketHeader packetHeader; PayloadHeader payloadHeader; uint16_t decodeSize; NL_TEST_ASSERT(inSuite, chip::Platform::MemoryInit() == CHIP_NO_ERROR); - for (unsigned i = 0; i < theTestVectorMsgExtensionsLength; i++) + for (const auto & testEntry : theTestVectorMsgExtensions) { - testEntry = &theTestVectorMsgExtensions[i]; - - System::PacketBufferHandle msg = System::PacketBufferHandle::NewWithData(testEntry->msg, testEntry->msgLength); + System::PacketBufferHandle msg = System::PacketBufferHandle::NewWithData(testEntry.msg, testEntry.msgLength); NL_TEST_ASSERT(inSuite, packetHeader.Decode(msg->Start(), msg->DataLength(), &decodeSize) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, decodeSize == testEntry->payloadOffset); + NL_TEST_ASSERT(inSuite, decodeSize == testEntry.payloadOffset); NL_TEST_ASSERT(inSuite, payloadHeader.Decode(msg->Start() + decodeSize, msg->DataLength(), &decodeSize) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, decodeSize == testEntry->appPayloadOffset); + NL_TEST_ASSERT(inSuite, decodeSize == testEntry.appPayloadOffset); } } diff --git a/src/transport/tests/TestCryptoContext.cpp b/src/transport/tests/TestCryptoContext.cpp index a88bacee9faa8c..9bcf0d25c7cbbb 100644 --- a/src/transport/tests/TestCryptoContext.cpp +++ b/src/transport/tests/TestCryptoContext.cpp @@ -48,19 +48,17 @@ struct PrivacyNonceTestEntry thePrivacyNonceTestVector[] = { }, }; -const uint16_t thePrivacyNonceTestVectorLength = sizeof(thePrivacyNonceTestVector) / sizeof(thePrivacyNonceTestVector[0]); - void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext) { - for (unsigned i = 0; i < thePrivacyNonceTestVectorLength; i++) + for (const auto & testVector : thePrivacyNonceTestVector) { MessageAuthenticationCode mic; - uint16_t sessionId = thePrivacyNonceTestVector[i].sessionId; - const ByteSpan expectedPrivacyNonce(thePrivacyNonceTestVector[i].privacyNonce, NONCE_LENGTH); + uint16_t sessionId = testVector.sessionId; + const ByteSpan expectedPrivacyNonce(testVector.privacyNonce, NONCE_LENGTH); CryptoContext::NonceStorage privacyNonce; CryptoContext::ConstNonceView privacyNonceView(privacyNonce); - mic.SetTag(nullptr, thePrivacyNonceTestVector[i].mic, MIC_LENGTH); + mic.SetTag(nullptr, testVector.mic, MIC_LENGTH); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == chip::CryptoContext::BuildPrivacyNonce(privacyNonce, sessionId, mic)); NL_TEST_ASSERT(apSuite, 0 == memcmp(privacyNonceView.data(), expectedPrivacyNonce.data(), NONCE_LENGTH)); diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index 633897c5c0043b..fcc4d7621b3af9 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -816,17 +816,17 @@ void SessionAllocationTest(nlTestSuite * inSuite, void * inContext) ScopedNodeId(NodeIdFromPAKEKeyId(kDefaultCommissioningPasscodeId), kUndefinedFabricIndex)); NL_TEST_ASSERT(inSuite, handle.HasValue()); auto potentialCollision = handle.Value()->AsSecureSession()->GetLocalSessionId(); - for (size_t h = 0; h < numHandles; ++h) + for (uint16_t sessionId : sessionIds) { - NL_TEST_ASSERT(inSuite, potentialCollision != sessionIds[h]); + NL_TEST_ASSERT(inSuite, potentialCollision != sessionId); } handle.Value()->AsSecureSession()->MarkForEviction(); } // Free our allocated sessions. - for (size_t h = 0; h < numHandles; ++h) + for (auto & handle : handles) { - handles[h].Value()->AsSecureSession()->MarkForEviction(); + handle.Value()->AsSecureSession()->MarkForEviction(); } }