From 4a055ebad97d5ccc13a1550394babcb807dca039 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 14:08:19 -0400 Subject: [PATCH 01/11] Modernize using: ``` ./scripts/run-clang-tidy-on-compile-commands.py --checks modernize-loop-convert --compile-database out/linux-x64-chip-tool-clang/compile_commands.json --export-fixes out/fixes.xml fix ``` --- .../chip-tool/commands/common/CHIPCommand.cpp | 4 +-- .../chip-tool/commands/common/Command.cpp | 7 ++--- src/app/BufferedReadCallback.cpp | 4 +-- .../pics/PICSBooleanExpressionParser.cpp | 3 +- src/ble/BleLayer.cpp | 4 +-- src/credentials/CHIPCert.cpp | 4 +-- .../DefaultDeviceAttestationVerifier.cpp | 6 ++-- .../AddressResolve_DefaultImpl.cpp | 4 +-- src/lib/asn1/ASN1OID.cpp | 20 ++++++------- src/lib/dnssd/minimal_mdns/ResponseSender.cpp | 30 +++++++++---------- .../dnssd/minimal_mdns/core/RecordWriter.cpp | 6 ++-- 11 files changed, 45 insertions(+), 47 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index c5edba6c3dd19f..6bee2d10cd2439 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -167,9 +167,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 & mCommissioner : mCommissioners) { - ShutdownCommissioner(it->first); + ShutdownCommissioner(mCommissioner.first); } StopTracing(); diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 6717bcbbc03216..34656df815b39a 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 & mArg : mArgs) { - if (mArgs[i].isOptional()) + if (mArg.isOptional()) { optionalArgsCount++; } @@ -877,9 +877,8 @@ void ResetOptionalArg(const Argument & arg) void Command::ResetArguments() { - for (size_t i = 0; i < mArgs.size(); i++) + for (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..34404d4f28f35a 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 (auto & i : mBufferedList) { - totalBufSize += mBufferedList[i]->TotalLength(); + totalBufSize += i->TotalLength(); } // 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..80764fb4b7be91 100644 --- a/src/ble/BleLayer.cpp +++ b/src/ble/BleLayer.cpp @@ -203,9 +203,9 @@ 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++) + for (unsigned char & mSupportedProtocolVersion : msg.mSupportedProtocolVersions) { - msg.mSupportedProtocolVersions[i] = chip::Encoding::Read8(p); + mSupportedProtocolVersion = chip::Encoding::Read8(p); } msg.mMtu = chip::Encoding::LittleEndian::Read16(p); diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp index e5167d05dea768..eb5ee88529ede2 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 & i : rdn) { - rdn[i].Clear(); + i.Clear(); } } diff --git a/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp b/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp index 70684157014515..456cf453710c37 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 & gCdSigningKey : gCdSigningKeys) { - if (kid.data_equal(gCdSigningKeys[keyIdx].mKid)) + if (kid.data_equal(gCdSigningKey.mKid)) { - outPubKey = gCdSigningKeys[keyIdx].mPubkey; + outPubKey = gCdSigningKey.mPubkey; return CHIP_NO_ERROR; } } diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 0bc8000138addf..7198ccee502d35 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 & mActiveLookup : mActiveLookups) { - System::Clock::Timeout timeout = it->NextEventTimeout(now); + System::Clock::Timeout timeout = mActiveLookup.NextEventTimeout(now); if (timeout < nextTimeout) { diff --git a/src/lib/asn1/ASN1OID.cpp b/src/lib/asn1/ASN1OID.cpp index 106e43c0e803df..496eaa1c1fda34 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 & i : sOIDTable) { - if (encodedOIDLen == sOIDTable[i].EncodedOIDLen && memcmp(encodedOID, sOIDTable[i].EncodedOID, encodedOIDLen) == 0) + if (encodedOIDLen == i.EncodedOIDLen && memcmp(encodedOID, i.EncodedOID, encodedOIDLen) == 0) { - return sOIDTable[i].EnumVal; + return i.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 & i : sOIDTable) { - if (oid == sOIDTable[i].EnumVal) + if (oid == i.EnumVal) { - encodedOID = sOIDTable[i].EncodedOID; - encodedOIDLen = sOIDTable[i].EncodedOIDLen; + encodedOID = i.EncodedOID; + encodedOIDLen = i.EncodedOIDLen; return true; } } @@ -95,11 +95,11 @@ const char * GetOIDName(OID oid) { return "NotSpecified"; } - for (uint32_t i = 0; i < sOIDTableSize; i++) + for (auto i : sOIDNameTable) { - if (oid == sOIDNameTable[i].EnumVal) + if (oid == i.EnumVal) { - return sOIDNameTable[i].Name; + return i.Name; } } return "Unknown"; diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp index 7c6220baa4b8dd..2964bac436f81a 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 & mResponder : mResponders) { - if (*it == nullptr || *it == queryResponder) + if (mResponder == nullptr || mResponder == queryResponder) { - *it = queryResponder; + mResponder = 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 mResponder : mResponders) { - if (*it != nullptr) + if (mResponder != 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 & mResponder : mResponders) { { - if (*it != nullptr) + if (mResponder != nullptr) { - (*it)->ResetAdditionals(); + mResponder->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 & mResponder : mResponders) { - if (*responder == nullptr) + if (mResponder == nullptr) { continue; } - for (auto it = (*responder)->begin(&responseFilter); it != (*responder)->end(); it++) + for (auto it = mResponder->begin(&responseFilter); it != mResponder->end(); it++) { it->responder->AddAllResponses(querySource, this, configuration); ReturnErrorOnFailure(mSendState.GetError()); - (*responder)->MarkAdditionalRepliesFor(it); + mResponder->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 & mResponder : mResponders) { - if (*responder == nullptr) + if (mResponder == nullptr) { continue; } - for (auto it = (*responder)->begin(&responseFilter); it != (*responder)->end(); it++) + for (auto it = mResponder->begin(&responseFilter); it != mResponder->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..2ff740acb223ed 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 & mPreviousQName : mPreviousQNames) { - if (mPreviousQNames[i] == kInvalidOffset) + if (mPreviousQName == kInvalidOffset) { - mPreviousQNames[i] = offset; + mPreviousQName = offset; return; } } From 0e4800405c4df9c3be62fcb5d493be33b4ce78c9 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 14:11:11 -0400 Subject: [PATCH 02/11] Fix using: ``` ./scripts/run-clang-tidy-on-compile-commands.py --checks modernize-loop-convert --compile-database out/linux-x64-all-clusters-clang/compile_commands.json --export-fixes out/fixes.xml fix ``` --- .../general-diagnostics-server/general-diagnostics-server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } From 8b3d1e345c3b70ae092c11dff4fac909fdf5cbf3 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 14:55:22 -0400 Subject: [PATCH 03/11] Modernize using: ``` ./scripts/run-clang-tidy-on-compile-commands.py --checks modernize-loop-convert --compile-database out/linux-x64-tests-clang/compile_commands.json --export-fixes out/fixes.xml fix ``` --- src/app/tests/TestAttributeValueEncoder.cpp | 4 ++-- src/app/tests/TestPendingNotificationMap.cpp | 4 ++-- src/app/tests/TestReadInteraction.cpp | 12 ++++++------ src/controller/tests/TestWriteChunking.cpp | 4 ++-- src/controller/tests/data_model/TestRead.cpp | 8 ++++---- .../tests/TestCertificationDeclaration.cpp | 12 +++--------- src/credentials/tests/TestChipCert.cpp | 18 +++++++----------- src/crypto/tests/CHIPCryptoPALTest.cpp | 4 ++-- .../tests/TestGroupOperationalCredentials.cpp | 10 +++++----- src/lib/dnssd/tests/TestTxtFields.cpp | 4 ++-- src/lib/support/tests/TestIntrusiveList.cpp | 18 +++++++++--------- src/lib/support/tests/TestPool.cpp | 4 ++-- src/lib/support/tests/TestPrivateHeap.cpp | 16 ++++++++-------- .../tests/TestReliableMessageProtocol.cpp | 4 ++-- .../TestDefaultSessionResumptionStorage.cpp | 12 ++++++------ src/system/tests/TestSystemPacketBuffer.cpp | 8 ++++---- src/system/tests/TestSystemTimer.cpp | 8 ++++---- src/transport/raw/tests/TestMessageHeader.cpp | 12 ++++++------ src/transport/tests/TestCryptoContext.cpp | 8 ++++---- src/transport/tests/TestSessionManager.cpp | 8 ++++---- 20 files changed, 84 insertions(+), 94 deletions(-) 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..c2403bc9151746 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 (unsigned char expectedEntryIndecie : expectedEntryIndecies) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == expectedEntryIndecies[i]); + NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == expectedEntryIndecie); ++iter; } NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 9a27ba771b9497..a1bfeed258964d 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,9 +2213,9 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte // // Allocate a number of clients // - for (int i = 0; i < 4; i++) + for (auto & pClient : pClients) { - pClients[i] = Platform::New(engine, &ctx.GetExchangeManager(), delegate, + pClient = Platform::New(engine, &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); } diff --git a/src/controller/tests/TestWriteChunking.cpp b/src/controller/tests/TestWriteChunking.cpp index bd27e649bd79d1..d0269e4acf08ab 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 & j : list) { - list[j] = ByteSpan(sByteSpanData, static_cast(i)); + j = 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/tests/TestCertificationDeclaration.cpp b/src/credentials/tests/TestCertificationDeclaration.cpp index 262ac5fe3e2461..ec3a39fe57f899 100644 --- a/src/credentials/tests/TestCertificationDeclaration.cpp +++ b/src/credentials/tests/TestCertificationDeclaration.cpp @@ -266,10 +266,8 @@ 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 +377,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 +408,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..68ffae6c4ec63c 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -430,20 +430,18 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext) // 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); 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); } } @@ -1139,9 +1137,8 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext) // clang-format on static const size_t sNumTestCases = ArraySize(sTestCases); - for (unsigned i = 0; i < sNumTestCases; i++) + for (auto testCase : sTestCases) { - const TestCase & testCase = sTestCases[i]; uint8_t certType; err = certSet.Init(1); @@ -1188,9 +1185,8 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext) // clang-format on static const size_t sNumTestCases = ArraySize(sTestCases); - for (unsigned i = 0; i < sNumTestCases; i++) + for (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..5b58e90981b5f3 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -249,9 +249,9 @@ 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 & vectorIndex : theAesCtrTestVector) { - const AesCtrTestEntry * vector = &theAesCtrTestVector[vectorIndex]; + const AesCtrTestEntry * vector = &vectorIndex; if (vector->plaintextLen > 0) { numOfTestsRan++; diff --git a/src/crypto/tests/TestGroupOperationalCredentials.cpp b/src/crypto/tests/TestGroupOperationalCredentials.cpp index b7493cc7d853a0..e4e088d14345d0 100644 --- a/src/crypto/tests/TestGroupOperationalCredentials.cpp +++ b/src/crypto/tests/TestGroupOperationalCredentials.cpp @@ -86,16 +86,16 @@ void TestDeriveGroupOperationalCredentials(nlTestSuite * apSuite, void * apConte { GroupOperationalCredentials opCreds; - for (unsigned i = 0; i < theGroupKeySetTestVectorLength; i++) + for (auto & i : theGroupKeySetTestVector) { - const ByteSpan epochKey(theGroupKeySetTestVector[i].epochKey, KEY_LENGTH); + const ByteSpan epochKey(i.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, opCreds.hash == 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)); + 0 == memcmp(opCreds.encryption_key, i.groupKeys->encryption_key, KEY_LENGTH)); + NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.privacy_key, i.groupKeys->privacy_key, KEY_LENGTH)); } } diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 53bf730763879f..8945569fac5d93 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 (unsigned char i : node.commissionData.rotatingId) { - if (node.commissionData.rotatingId[i] != 0) + if (i != 0) { return false; } diff --git a/src/lib/support/tests/TestIntrusiveList.cpp b/src/lib/support/tests/TestIntrusiveList.cpp index ddb121b1262355..f81a7474fac624 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 & i : node) { switch (std::rand() % 5) { case 0: // PushFront - l1.PushFront(&node[i]); - l2.push_front(&node[i]); + l1.PushFront(&i); + l2.push_front(&i); break; case 1: // PushBack - l1.PushBack(&node[i]); - l2.push_back(&node[i]); + l1.PushBack(&i); + l2.push_back(&i); break; case 2: // InsertBefore op([&](auto & l1p, auto & l2p) { - l1.InsertBefore(l1p, &node[i]); - l2.insert(l2p, &node[i]); + l1.InsertBefore(l1p, &i); + l2.insert(l2p, &i); }); break; case 3: // InsertAfter op([&](auto & l1p, auto & l2p) { - l1.InsertAfter(l1p, &node[i]); - l2.insert(++l2p, &node[i]); + l1.InsertAfter(l1p, &i); + l2.insert(++l2p, &i); }); break; case 4: // Remove diff --git a/src/lib/support/tests/TestPool.cpp b/src/lib/support/tests/TestPool.cpp index 4a9f7d808062d1..cc6504eae705d2 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 & i : objs2) { - objs2[i] = pool.CreateObject(objs1); + i = 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..dd47103b7c0826 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -1651,9 +1651,9 @@ 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 (auto & i : theBackoffComplianceTestVector) { - struct BackoffComplianceTestVector * test = &theBackoffComplianceTestVector[i]; + struct BackoffComplianceTestVector * test = &i; System::Clock::Timeout backoff = ReliableMessageMgr::GetBackoff(test->backoffBase, test->sendCount); ChipLogProgress(Test, "Backoff base %" PRIu32 " # %d: %" PRIu32, test->backoffBase.count(), test->sendCount, backoff.count()); diff --git a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp index ca3d673b53fd14..b28ed3d83ad15e 100644 --- a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp +++ b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp @@ -299,26 +299,26 @@ 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{}) == + 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) != + sessionStorage.FindByScopedNodeId(vector.node, outResumptionId, outSharedSecret, outCats) != CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, - sessionStorage.FindByResumptionId(vectors[i].resumptionId, outNode, outSharedSecret, outCats) != + sessionStorage.FindByResumptionId(vector.resumptionId, outNode, outSharedSecret, outCats) != CHIP_NO_ERROR); } diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index 92cedf5f3b9427..1eca4482ea2039 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 (unsigned char & i : lPayload) { - lPayload[i] = static_cast(random()); + i = 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..7e613f9de3877d 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 i : gCallbackProcessed) { - NL_TEST_ASSERT(suite, (gCallbackProcessed[i] == 0) || (gCallbackProcessed[i] == 1)); + NL_TEST_ASSERT(suite, (i == 0) || (i == 1)); } } unsigned ExecutedTimerCount() { unsigned count = 0; - for (unsigned i = 0; i < kCancelTimerCount; i++) + for (int i : gCallbackProcessed) { - if (gCallbackProcessed[i] != 0) + if (i != 0) { count++; } diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index 1ad9b7b1e03d64..ad4f969089c916 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -381,10 +381,10 @@ void TestSpecComplianceEncode(nlTestSuite * inSuite, void * inContext) uint8_t buffer[MAX_FIXED_HEADER_SIZE]; uint16_t encodeSize; - for (unsigned i = 0; i < theSpecComplianceTestVectorLength; i++) + for (auto & i : theSpecComplianceTestVector) { PacketHeader packetHeader; - testEntry = &theSpecComplianceTestVector[i]; + testEntry = &i; packetHeader.SetMessageFlags(testEntry->messageFlags); packetHeader.SetSecurityFlags(testEntry->securityFlags); @@ -408,9 +408,9 @@ void TestSpecComplianceDecode(nlTestSuite * inSuite, void * inContext) PacketHeader packetHeader; uint16_t decodeSize; - for (unsigned i = 0; i < theSpecComplianceTestVectorLength; i++) + for (auto & i : theSpecComplianceTestVector) { - testEntry = &theSpecComplianceTestVector[i]; + testEntry = &i; NL_TEST_ASSERT(inSuite, packetHeader.Decode(testEntry->encoded, testEntry->size, &decodeSize) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, decodeSize == testEntry->size); @@ -528,9 +528,9 @@ void TestMsgExtensionsDecode(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, chip::Platform::MemoryInit() == CHIP_NO_ERROR); - for (unsigned i = 0; i < theTestVectorMsgExtensionsLength; i++) + for (auto & theTestVectorMsgExtension : theTestVectorMsgExtensions) { - testEntry = &theTestVectorMsgExtensions[i]; + testEntry = &theTestVectorMsgExtension; System::PacketBufferHandle msg = System::PacketBufferHandle::NewWithData(testEntry->msg, testEntry->msgLength); diff --git a/src/transport/tests/TestCryptoContext.cpp b/src/transport/tests/TestCryptoContext.cpp index a88bacee9faa8c..fd6f70dd418c1c 100644 --- a/src/transport/tests/TestCryptoContext.cpp +++ b/src/transport/tests/TestCryptoContext.cpp @@ -52,15 +52,15 @@ const uint16_t thePrivacyNonceTestVectorLength = sizeof(thePrivacyNonceTestVecto void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext) { - for (unsigned i = 0; i < thePrivacyNonceTestVectorLength; i++) + for (auto & i : thePrivacyNonceTestVector) { MessageAuthenticationCode mic; - uint16_t sessionId = thePrivacyNonceTestVector[i].sessionId; - const ByteSpan expectedPrivacyNonce(thePrivacyNonceTestVector[i].privacyNonce, NONCE_LENGTH); + uint16_t sessionId = i.sessionId; + const ByteSpan expectedPrivacyNonce(i.privacyNonce, NONCE_LENGTH); CryptoContext::NonceStorage privacyNonce; CryptoContext::ConstNonceView privacyNonceView(privacyNonce); - mic.SetTag(nullptr, thePrivacyNonceTestVector[i].mic, MIC_LENGTH); + mic.SetTag(nullptr, i.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..a1e2128f2624df 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 (unsigned short 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(); } } From 1851a4bce9e297fc74ba61521db44b6267cd23bb Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 15:28:52 -0400 Subject: [PATCH 04/11] Restyle and remove unused variable --- src/app/tests/TestReadInteraction.cpp | 2 +- src/credentials/tests/TestChipCert.cpp | 6 ++---- src/crypto/tests/TestGroupOperationalCredentials.cpp | 3 +-- .../tests/TestDefaultSessionResumptionStorage.cpp | 9 +++------ 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index a1bfeed258964d..92f6d964a8caa7 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -2216,7 +2216,7 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte for (auto & pClient : pClients) { pClient = Platform::New(engine, &ctx.GetExchangeManager(), delegate, - chip::app::ReadClient::InteractionType::Subscribe); + chip::app::ReadClient::InteractionType::Subscribe); } // diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index 68ffae6c4ec63c..90ba14ed5bc775 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -428,20 +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 (const auto & testCase : sValidationTestCases) { const ChipCertificateData * resultCert = nullptr; - err = certSet.Init(kMaxCertsPerTestCase); + err = certSet.Init(kMaxCertsPerTestCase); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); for (auto InputCert : testCase.InputCerts) { if (InputCert.Type != TestCert::kNone) { - err = LoadTestCert(certSet, InputCert.Type, InputCert.LoadFlags, - InputCert.DecodeFlags); + err = LoadTestCert(certSet, InputCert.Type, InputCert.LoadFlags, InputCert.DecodeFlags); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } } diff --git a/src/crypto/tests/TestGroupOperationalCredentials.cpp b/src/crypto/tests/TestGroupOperationalCredentials.cpp index e4e088d14345d0..0dc62d5120872e 100644 --- a/src/crypto/tests/TestGroupOperationalCredentials.cpp +++ b/src/crypto/tests/TestGroupOperationalCredentials.cpp @@ -93,8 +93,7 @@ void TestDeriveGroupOperationalCredentials(nlTestSuite * apSuite, void * apConte CHIP_NO_ERROR == Crypto::DeriveGroupOperationalCredentials(epochKey, kCompressedFabricId1, opCreds)); NL_TEST_ASSERT(apSuite, opCreds.hash == i.groupKeys->hash); - NL_TEST_ASSERT(apSuite, - 0 == memcmp(opCreds.encryption_key, i.groupKeys->encryption_key, KEY_LENGTH)); + NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.encryption_key, i.groupKeys->encryption_key, KEY_LENGTH)); NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.privacy_key, i.groupKeys->privacy_key, KEY_LENGTH)); } } diff --git a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp index b28ed3d83ad15e..4f9257e350d8ad 100644 --- a/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp +++ b/src/protocols/secure_channel/tests/TestDefaultSessionResumptionStorage.cpp @@ -302,8 +302,7 @@ void TestDelete(nlTestSuite * inSuite, void * inContext) for (auto & vector : vectors) { NL_TEST_ASSERT(inSuite, - sessionStorage.Save(vector.node, vector.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. @@ -315,11 +314,9 @@ void TestDelete(nlTestSuite * inSuite, void * inContext) chip::CATValues outCats; NL_TEST_ASSERT(inSuite, sessionStorage.Delete(vector.node) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, - sessionStorage.FindByScopedNodeId(vector.node, outResumptionId, outSharedSecret, outCats) != - CHIP_NO_ERROR); + sessionStorage.FindByScopedNodeId(vector.node, outResumptionId, outSharedSecret, outCats) != CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, - sessionStorage.FindByResumptionId(vector.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. From 20fbda04391239e878587caec5e593d3c590665b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 16:05:54 -0400 Subject: [PATCH 05/11] Remove more unused variables for array sizes --- .../tests/TestCertificationDeclaration.cpp | 2 -- src/credentials/tests/TestChipCert.cpp | 4 ---- src/crypto/tests/CHIPCryptoPALTest.cpp | 24 +++++++++---------- .../tests/TestGroupOperationalCredentials.cpp | 2 -- .../tests/TestReliableMessageProtocol.cpp | 3 --- src/transport/raw/tests/TestMessageHeader.cpp | 20 +++++++--------- src/transport/tests/TestCryptoContext.cpp | 2 -- 7 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/credentials/tests/TestCertificationDeclaration.cpp b/src/credentials/tests/TestCertificationDeclaration.cpp index ec3a39fe57f899..7150db4a44eacf 100644 --- a/src/credentials/tests/TestCertificationDeclaration.cpp +++ b/src/credentials/tests/TestCertificationDeclaration.cpp @@ -262,8 +262,6 @@ 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 (const auto & testCase : sTestCases) diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index 90ba14ed5bc775..abc66789240c53 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -1133,8 +1133,6 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, kCertType_Node }, }; // clang-format on - static const size_t sNumTestCases = ArraySize(sTestCases); - for (auto testCase : sTestCases) { uint8_t certType; @@ -1181,8 +1179,6 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, 0xDEDEDEDE00020002 }, }; // clang-format on - static const size_t sNumTestCases = ArraySize(sTestCases); - for (auto testCase : sTestCases) { uint64_t chipId; diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 5b58e90981b5f3..0b705d27a05355 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -193,19 +193,17 @@ const AesCtrTestEntry theAesCtrTestVector[] = { .ciphertextLen = 16, }, { - .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", - .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", - .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", - .plaintextLen = 32, - .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" - "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", + .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", + .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", + .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + .plaintextLen = 32, + .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" + "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", .ciphertextLen = 32, } }; -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; @@ -1336,8 +1334,8 @@ void TestCSR_GenDirect(nlTestSuite * inSuite, void * inContext) // Let's corrupt the CSR buffer and make sure it fails to verify size_t length = csrSpan.size(); - csrBuf[length - 2] = (uint8_t)(csrBuf[length - 2] + 1); - csrBuf[length - 1] = (uint8_t)(csrBuf[length - 1] + 1); + csrBuf[length - 2] = (uint8_t) (csrBuf[length - 2] + 1); + csrBuf[length - 1] = (uint8_t) (csrBuf[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csrSpan.data(), csrSpan.size(), pubkey) != CHIP_NO_ERROR); } @@ -1367,8 +1365,8 @@ static void TestCSR_GenByKeypair(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, memcmp(pubkey.ConstBytes(), keypair.Pubkey().ConstBytes(), pubkey.Length()) == 0); // Let's corrupt the CSR buffer and make sure it fails to verify - csr[length - 2] = (uint8_t)(csr[length - 2] + 1); - csr[length - 1] = (uint8_t)(csr[length - 1] + 1); + csr[length - 2] = (uint8_t) (csr[length - 2] + 1); + csr[length - 1] = (uint8_t) (csr[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csr, length, pubkey) != CHIP_NO_ERROR); } diff --git a/src/crypto/tests/TestGroupOperationalCredentials.cpp b/src/crypto/tests/TestGroupOperationalCredentials.cpp index 0dc62d5120872e..ab27cea3209344 100644 --- a/src/crypto/tests/TestGroupOperationalCredentials.cpp +++ b/src/crypto/tests/TestGroupOperationalCredentials.cpp @@ -80,8 +80,6 @@ struct GroupKeySetTestEntry theGroupKeySetTestVector[] = { }, }; -const uint16_t theGroupKeySetTestVectorLength = sizeof(theGroupKeySetTestVector) / sizeof(theGroupKeySetTestVector[0]); - void TestDeriveGroupOperationalCredentials(nlTestSuite * apSuite, void * apContext) { GroupOperationalCredentials opCreds; diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index dd47103b7c0826..0c17f1b6d61cb6 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); diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index ad4f969089c916..39167b5d0ad4c1 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -373,8 +373,6 @@ struct SpecComplianceTestVector theSpecComplianceTestVector[] = { }, }; -const unsigned theSpecComplianceTestVectorLength = sizeof(theSpecComplianceTestVector) / sizeof(struct SpecComplianceTestVector); - void TestSpecComplianceEncode(nlTestSuite * inSuite, void * inContext) { struct SpecComplianceTestVector * testEntry; @@ -437,7 +435,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test MX ================== { @@ -446,7 +444,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=none, MX=1, SX=0 @@ -454,7 +452,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + PRO_LEN + APP_LEN, .msg = "\x04\x00\x00\x20\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=none, DST=1, MX=1, SX=0 @@ -462,7 +460,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + DST_LEN + PRO_LEN + APP_LEN, .msg = "\x01\x00\x00\x20\xCC\xCC\xCC\xCC\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=0 @@ -479,7 +477,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x02\x00\x00\x21\xCC\xCC\xCC\xCC\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=group, MX=1, SX=0 @@ -487,7 +485,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x06\x00\x00\x21\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test SX ================== { @@ -496,7 +494,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=none, DST=none, MX=1, SX=1 @@ -504,7 +502,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=1 @@ -517,8 +515,6 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { }, }; -const unsigned theTestVectorMsgExtensionsLength = sizeof(theTestVectorMsgExtensions) / sizeof(struct TestVectorMsgExtensions); - void TestMsgExtensionsDecode(nlTestSuite * inSuite, void * inContext) { struct TestVectorMsgExtensions * testEntry; diff --git a/src/transport/tests/TestCryptoContext.cpp b/src/transport/tests/TestCryptoContext.cpp index fd6f70dd418c1c..f65900040aee54 100644 --- a/src/transport/tests/TestCryptoContext.cpp +++ b/src/transport/tests/TestCryptoContext.cpp @@ -48,8 +48,6 @@ struct PrivacyNonceTestEntry thePrivacyNonceTestVector[] = { }, }; -const uint16_t thePrivacyNonceTestVectorLength = sizeof(thePrivacyNonceTestVector) / sizeof(thePrivacyNonceTestVector[0]); - void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext) { for (auto & i : thePrivacyNonceTestVector) From 5b736b5232732118a8ffb4863d5d11034bfa8fdd Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 2 Nov 2022 16:06:14 -0400 Subject: [PATCH 06/11] Restyle --- src/crypto/tests/CHIPCryptoPALTest.cpp | 22 +++++++++---------- src/transport/raw/tests/TestMessageHeader.cpp | 16 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 0b705d27a05355..e620366a9ddd2d 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -193,13 +193,13 @@ const AesCtrTestEntry theAesCtrTestVector[] = { .ciphertextLen = 16, }, { - .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", - .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", - .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", - .plaintextLen = 32, - .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" - "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", + .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", + .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", + .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + .plaintextLen = 32, + .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" + "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", .ciphertextLen = 32, } }; @@ -1334,8 +1334,8 @@ void TestCSR_GenDirect(nlTestSuite * inSuite, void * inContext) // Let's corrupt the CSR buffer and make sure it fails to verify size_t length = csrSpan.size(); - csrBuf[length - 2] = (uint8_t) (csrBuf[length - 2] + 1); - csrBuf[length - 1] = (uint8_t) (csrBuf[length - 1] + 1); + csrBuf[length - 2] = (uint8_t)(csrBuf[length - 2] + 1); + csrBuf[length - 1] = (uint8_t)(csrBuf[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csrSpan.data(), csrSpan.size(), pubkey) != CHIP_NO_ERROR); } @@ -1365,8 +1365,8 @@ static void TestCSR_GenByKeypair(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, memcmp(pubkey.ConstBytes(), keypair.Pubkey().ConstBytes(), pubkey.Length()) == 0); // Let's corrupt the CSR buffer and make sure it fails to verify - csr[length - 2] = (uint8_t) (csr[length - 2] + 1); - csr[length - 1] = (uint8_t) (csr[length - 1] + 1); + csr[length - 2] = (uint8_t)(csr[length - 2] + 1); + csr[length - 1] = (uint8_t)(csr[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csr, length, pubkey) != CHIP_NO_ERROR); } diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index 39167b5d0ad4c1..78922013e83c66 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -435,7 +435,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test MX ================== { @@ -444,7 +444,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=none, MX=1, SX=0 @@ -452,7 +452,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + PRO_LEN + APP_LEN, .msg = "\x04\x00\x00\x20\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=none, DST=1, MX=1, SX=0 @@ -460,7 +460,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + DST_LEN + PRO_LEN + APP_LEN, .msg = "\x01\x00\x00\x20\xCC\xCC\xCC\xCC\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=0 @@ -477,7 +477,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x02\x00\x00\x21\xCC\xCC\xCC\xCC\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=group, MX=1, SX=0 @@ -485,7 +485,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x06\x00\x00\x21\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test SX ================== { @@ -494,7 +494,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=none, DST=none, MX=1, SX=1 @@ -502,7 +502,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=1 From 7626aeed7e1540c208e7f632f6265496346ce069 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 3 Nov 2022 10:29:18 -0400 Subject: [PATCH 07/11] Start some manual renames of iteration values ... automated tool is quite silly --- examples/chip-tool/commands/common/CHIPCommand.cpp | 4 ++-- examples/chip-tool/commands/common/Command.cpp | 8 ++++---- src/app/BufferedReadCallback.cpp | 4 ++-- src/app/tests/TestPendingNotificationMap.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 6bee2d10cd2439..9c697477cd5084 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -167,9 +167,9 @@ void CHIPCommand::MaybeTearDownStack() // since the CHIP thread and event queue have been stopped, preventing any thread // races. // - for (auto & mCommissioner : mCommissioners) + for (auto & commissioner : mCommissioners) { - ShutdownCommissioner(mCommissioner.first); + ShutdownCommissioner(commissioner.first); } StopTracing(); diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 34656df815b39a..744af330b09616 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 (auto & mArg : mArgs) + for (auto & arg : mArgs) { - if (mArg.isOptional()) + if (arg.isOptional()) { optionalArgsCount++; } @@ -55,7 +55,7 @@ bool Command::InitArguments(int argc, char ** argv) } } - VerifyOrExit((size_t)(argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), + VerifyOrExit((size_t) (argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), ChipLogError(chipTool, "InitArgs: Wrong arguments number: %d instead of %u", argc, static_cast(mandatoryArgsCount))); @@ -877,7 +877,7 @@ void ResetOptionalArg(const Argument & arg) void Command::ResetArguments() { - for (auto arg : mArgs) + for (const auto & arg : mArgs) { const ArgumentType type = arg.type; if (arg.isOptional()) diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 34404d4f28f35a..28b38fe5366a41 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 (auto & i : mBufferedList) + for (const auto & list : mBufferedList) { - totalBufSize += i->TotalLength(); + totalBufSize += list->TotalLength(); } // diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp index c2403bc9151746..e8facbb1dc65b2 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 (unsigned char expectedEntryIndecie : expectedEntryIndecies) + for (unsigned char ch : expectedEntryIndecies) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == expectedEntryIndecie); + NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == ch); ++iter; } NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); From 63856677fa525a8e1f06c22213c6a2eddbb2b6d2 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 3 Nov 2022 10:48:06 -0400 Subject: [PATCH 08/11] More manual updates for naming of things. Code should be cleaner now --- .../chip-tool/commands/common/Command.cpp | 2 +- src/app/tests/TestReadInteraction.cpp | 6 +- src/ble/BleLayer.cpp | 6 +- src/controller/tests/TestWriteChunking.cpp | 14 ++-- src/credentials/CHIPCert.cpp | 4 +- .../DefaultDeviceAttestationVerifier.cpp | 6 +- src/credentials/tests/TestChipCert.cpp | 10 +-- src/crypto/tests/CHIPCryptoPALTest.cpp | 31 +++++---- .../tests/TestGroupOperationalCredentials.cpp | 10 +-- .../AddressResolve_DefaultImpl.cpp | 4 +- src/lib/asn1/ASN1OID.cpp | 20 +++--- src/lib/dnssd/minimal_mdns/ResponseSender.cpp | 30 ++++----- .../dnssd/minimal_mdns/core/RecordWriter.cpp | 6 +- src/lib/dnssd/tests/TestTxtFields.cpp | 4 +- src/lib/support/tests/TestIntrusiveList.cpp | 18 ++--- src/lib/support/tests/TestPool.cpp | 4 +- .../tests/TestReliableMessageProtocol.cpp | 11 ++-- src/system/tests/TestSystemPacketBuffer.cpp | 4 +- src/system/tests/TestSystemTimer.cpp | 8 +-- src/transport/raw/MessageHeader.h | 4 +- src/transport/raw/tests/TestMessageHeader.cpp | 66 ++++++++----------- src/transport/tests/TestCryptoContext.cpp | 8 +-- 22 files changed, 134 insertions(+), 142 deletions(-) diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 744af330b09616..59d678158ed073 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -55,7 +55,7 @@ bool Command::InitArguments(int argc, char ** argv) } } - VerifyOrExit((size_t) (argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), + VerifyOrExit((size_t)(argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), ChipLogError(chipTool, "InitArgs: Wrong arguments number: %d instead of %u", argc, static_cast(mandatoryArgsCount))); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 92f6d964a8caa7..b52d0ffec702cc 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -2213,10 +2213,10 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte // // Allocate a number of clients // - for (auto & pClient : pClients) + for (auto & client : pClients) { - pClient = 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/ble/BleLayer.cpp b/src/ble/BleLayer.cpp index 80764fb4b7be91..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 (unsigned char & mSupportedProtocolVersion : msg.mSupportedProtocolVersions) + static_assert(kCapabilitiesRequestSupportedVersionsLength == sizeof(msg.mSupportedProtocolVersions), + "Expected capability sizes and storage must match"); + for (unsigned char & version : msg.mSupportedProtocolVersions) { - mSupportedProtocolVersion = 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 d0269e4acf08ab..c27b53b56cc099 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 (auto & j : list) + for (auto & item : list) { - j = ByteSpan(sByteSpanData, static_cast(i)); + item = ByteSpan(sByteSpanData, static_cast(i)); } err = writeClient.EncodeAttribute(attributePath, app::DataModel::List(list, kTestListLength)); @@ -634,7 +634,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute2) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute2) }, .expectedStatus = { true, true }, }); @@ -660,7 +660,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kNull, ListData::kList }, .expectedStatus = { true }, }); @@ -671,7 +671,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kList, ListData::kNull }, .expectedStatus = { true }, }); @@ -682,8 +682,8 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kList, ListData::kNull, ListData::kList }, .expectedStatus = { true }, }); diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp index eb5ee88529ede2..c2a4ba424af2a7 100644 --- a/src/credentials/CHIPCert.cpp +++ b/src/credentials/CHIPCert.cpp @@ -616,9 +616,9 @@ ChipDN::~ChipDN() {} void ChipDN::Clear() { - for (auto & i : rdn) + for (auto & dn : rdn) { - i.Clear(); + dn.Clear(); } } diff --git a/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp b/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp index 456cf453710c37..6c2cad430b63a6 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 (auto & gCdSigningKey : gCdSigningKeys) + for (auto & CdSigningKey : gCdSigningKeys) { - if (kid.data_equal(gCdSigningKey.mKid)) + if (kid.data_equal(CdSigningKey.mKid)) { - outPubKey = gCdSigningKey.mPubkey; + outPubKey = CdSigningKey.mPubkey; return CHIP_NO_ERROR; } } diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index abc66789240c53..d3610b5f4ab49e 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -435,11 +435,11 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext) err = certSet.Init(kMaxCertsPerTestCase); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - for (auto InputCert : testCase.InputCerts) + for (auto inputCert : testCase.InputCerts) { - if (InputCert.Type != TestCert::kNone) + if (inputCert.Type != TestCert::kNone) { - err = LoadTestCert(certSet, InputCert.Type, InputCert.LoadFlags, InputCert.DecodeFlags); + err = LoadTestCert(certSet, inputCert.Type, inputCert.LoadFlags, inputCert.DecodeFlags); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } } @@ -1133,7 +1133,7 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, kCertType_Node }, }; // clang-format on - for (auto testCase : sTestCases) + for (const auto & testCase : sTestCases) { uint8_t certType; @@ -1179,7 +1179,7 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext) { TestCert::kNode02_02, 0xDEDEDEDE00020002 }, }; // clang-format on - for (auto testCase : sTestCases) + for (const auto & testCase : sTestCases) { uint64_t chipId; diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index e620366a9ddd2d..f3396012b33305 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -193,13 +193,13 @@ const AesCtrTestEntry theAesCtrTestVector[] = { .ciphertextLen = 16, }, { - .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", - .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", - .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", - .plaintextLen = 32, - .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" - "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", + .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", + .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", + .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + .plaintextLen = 32, + .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" + "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", .ciphertextLen = 32, } }; @@ -247,14 +247,13 @@ static void TestAES_CTR_128CryptTestVectors(nlTestSuite * inSuite, void * inCont { HeapChecker heapChecker(inSuite); int numOfTestsRan = 0; - for (const auto & vectorIndex : theAesCtrTestVector) + for (const auto & vector : theAesCtrTestVector) { - const AesCtrTestEntry * vector = &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); @@ -1334,8 +1333,8 @@ void TestCSR_GenDirect(nlTestSuite * inSuite, void * inContext) // Let's corrupt the CSR buffer and make sure it fails to verify size_t length = csrSpan.size(); - csrBuf[length - 2] = (uint8_t)(csrBuf[length - 2] + 1); - csrBuf[length - 1] = (uint8_t)(csrBuf[length - 1] + 1); + csrBuf[length - 2] = (uint8_t) (csrBuf[length - 2] + 1); + csrBuf[length - 1] = (uint8_t) (csrBuf[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csrSpan.data(), csrSpan.size(), pubkey) != CHIP_NO_ERROR); } @@ -1365,8 +1364,8 @@ static void TestCSR_GenByKeypair(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, memcmp(pubkey.ConstBytes(), keypair.Pubkey().ConstBytes(), pubkey.Length()) == 0); // Let's corrupt the CSR buffer and make sure it fails to verify - csr[length - 2] = (uint8_t)(csr[length - 2] + 1); - csr[length - 1] = (uint8_t)(csr[length - 1] + 1); + csr[length - 2] = (uint8_t) (csr[length - 2] + 1); + csr[length - 1] = (uint8_t) (csr[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csr, length, pubkey) != CHIP_NO_ERROR); } diff --git a/src/crypto/tests/TestGroupOperationalCredentials.cpp b/src/crypto/tests/TestGroupOperationalCredentials.cpp index ab27cea3209344..1f0eeb5f17e503 100644 --- a/src/crypto/tests/TestGroupOperationalCredentials.cpp +++ b/src/crypto/tests/TestGroupOperationalCredentials.cpp @@ -84,15 +84,15 @@ void TestDeriveGroupOperationalCredentials(nlTestSuite * apSuite, void * apConte { GroupOperationalCredentials opCreds; - for (auto & i : theGroupKeySetTestVector) + for (const auto & testVector : theGroupKeySetTestVector) { - const ByteSpan epochKey(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 == i.groupKeys->hash); - NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.encryption_key, i.groupKeys->encryption_key, KEY_LENGTH)); - NL_TEST_ASSERT(apSuite, 0 == memcmp(opCreds.privacy_key, 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 7198ccee502d35..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 & mActiveLookup : mActiveLookups) + for (auto & activeLookup : mActiveLookups) { - System::Clock::Timeout timeout = mActiveLookup.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 496eaa1c1fda34..5e43dff9c97a1e 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 (const auto & i : sOIDTable) + for (const auto & oid : sOIDTable) { - if (encodedOIDLen == i.EncodedOIDLen && memcmp(encodedOID, i.EncodedOID, encodedOIDLen) == 0) + if (encodedOIDLen == oid.EncodedOIDLen && memcmp(encodedOID, oid.EncodedOID, encodedOIDLen) == 0) { - return i.EnumVal; + return oid.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 (const auto & i : sOIDTable) + for (const auto & tableEntry : sOIDTable) { - if (oid == i.EnumVal) + if (oid == tableEntry.EnumVal) { - encodedOID = i.EncodedOID; - encodedOIDLen = i.EncodedOIDLen; + encodedOID = tableEntry.EncodedOID; + encodedOIDLen = tableEntry.EncodedOIDLen; return true; } } @@ -95,11 +95,11 @@ const char * GetOIDName(OID oid) { return "NotSpecified"; } - for (auto i : sOIDNameTable) + for (const auto & tableEntry : sOIDNameTable) { - if (oid == i.EnumVal) + if (oid == tableEntry.EnumVal) { - return 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 2964bac436f81a..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 & mResponder : mResponders) + for (auto & responder : mResponders) { - if (mResponder == nullptr || mResponder == queryResponder) + if (responder == nullptr || responder == queryResponder) { - mResponder = queryResponder; + responder = queryResponder; return CHIP_NO_ERROR; } } @@ -90,9 +90,9 @@ CHIP_ERROR ResponseSender::RemoveQueryResponder(QueryResponderBase * queryRespon bool ResponseSender::HasQueryResponders() const { - for (auto mResponder : mResponders) + for (auto responder : mResponders) { - if (mResponder != 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 & mResponder : mResponders) + for (auto & responder : mResponders) { { - if (mResponder != nullptr) + if (responder != nullptr) { - mResponder->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 & mResponder : mResponders) + for (auto & responder : mResponders) { - if (mResponder == nullptr) + if (responder == nullptr) { continue; } - for (auto it = mResponder->begin(&responseFilter); it != mResponder->end(); it++) + for (auto it = responder->begin(&responseFilter); it != responder->end(); it++) { it->responder->AddAllResponses(querySource, this, configuration); ReturnErrorOnFailure(mSendState.GetError()); - mResponder->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 & mResponder : mResponders) + for (auto & responder : mResponders) { - if (mResponder == nullptr) + if (responder == nullptr) { continue; } - for (auto it = mResponder->begin(&responseFilter); it != mResponder->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 2ff740acb223ed..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 (unsigned short & mPreviousQName : mPreviousQNames) + for (unsigned short & previousName : mPreviousQNames) { - if (mPreviousQName == kInvalidOffset) + if (previousName == kInvalidOffset) { - mPreviousQName = offset; + previousName = offset; return; } } diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 8945569fac5d93..87d1e16e0ec4a0 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 (unsigned char i : node.commissionData.rotatingId) + for (unsigned char id : node.commissionData.rotatingId) { - if (i != 0) + if (id != 0) { return false; } diff --git a/src/lib/support/tests/TestIntrusiveList.cpp b/src/lib/support/tests/TestIntrusiveList.cpp index f81a7474fac624..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 (auto & i : node) + for (auto & n : node) { switch (std::rand() % 5) { case 0: // PushFront - l1.PushFront(&i); - l2.push_front(&i); + l1.PushFront(&n); + l2.push_front(&n); break; case 1: // PushBack - l1.PushBack(&i); - l2.push_back(&i); + l1.PushBack(&n); + l2.push_back(&n); break; case 2: // InsertBefore op([&](auto & l1p, auto & l2p) { - l1.InsertBefore(l1p, &i); - l2.insert(l2p, &i); + l1.InsertBefore(l1p, &n); + l2.insert(l2p, &n); }); break; case 3: // InsertAfter op([&](auto & l1p, auto & l2p) { - l1.InsertAfter(l1p, &i); - l2.insert(++l2p, &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 cc6504eae705d2..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 (auto & i : objs2) + for (auto & obj : 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/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index 0c17f1b6d61cb6..eb8661550376df 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -1648,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 (auto & i : theBackoffComplianceTestVector) + for (const auto & test : theBackoffComplianceTestVector) { - struct BackoffComplianceTestVector * test = &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/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index 1eca4482ea2039..a3c082cb12d889 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -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 (unsigned char & i : lPayload) + for (unsigned char & payload : 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 7e613f9de3877d..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 (int i : gCallbackProcessed) + for (int processed : gCallbackProcessed) { - NL_TEST_ASSERT(suite, (i == 0) || (i == 1)); + NL_TEST_ASSERT(suite, (processed == 0) || (processed == 1)); } } unsigned ExecutedTimerCount() { unsigned count = 0; - for (int i : gCallbackProcessed) + for (int processed : gCallbackProcessed) { - if (i != 0) + if (processed != 0) { count++; } diff --git a/src/transport/raw/MessageHeader.h b/src/transport/raw/MessageHeader.h index 5589647bd9ebc9..4012faa57c8a59 100644 --- a/src/transport/raw/MessageHeader.h +++ b/src/transport/raw/MessageHeader.h @@ -430,7 +430,7 @@ class PayloadHeader { public: constexpr PayloadHeader() { SetProtocol(Protocols::NotSpecified); } - constexpr PayloadHeader(const PayloadHeader &) = default; + constexpr PayloadHeader(const PayloadHeader &) = default; PayloadHeader & operator=(const PayloadHeader &) = default; /** Get the Session ID from this header. */ @@ -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 78922013e83c66..eb10a7df3f630e 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -375,48 +375,43 @@ struct SpecComplianceTestVector theSpecComplianceTestVector[] = { void TestSpecComplianceEncode(nlTestSuite * inSuite, void * inContext) { - struct SpecComplianceTestVector * testEntry; uint8_t buffer[MAX_FIXED_HEADER_SIZE]; uint16_t encodeSize; - for (auto & i : theSpecComplianceTestVector) + for (const auto & testEntry : theSpecComplianceTestVector) { PacketHeader packetHeader; - testEntry = &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 (auto & i : theSpecComplianceTestVector) + for (const auto & testEntry : theSpecComplianceTestVector) { - testEntry = &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); } } @@ -435,7 +430,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test MX ================== { @@ -444,7 +439,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=none, MX=1, SX=0 @@ -452,7 +447,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + PRO_LEN + APP_LEN, .msg = "\x04\x00\x00\x20\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=none, DST=1, MX=1, SX=0 @@ -460,7 +455,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + DST_LEN + PRO_LEN + APP_LEN, .msg = "\x01\x00\x00\x20\xCC\xCC\xCC\xCC\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=0 @@ -477,7 +472,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x02\x00\x00\x21\xCC\xCC\xCC\xCC\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=group, MX=1, SX=0 @@ -485,7 +480,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x06\x00\x00\x21\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test SX ================== { @@ -494,7 +489,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=none, DST=none, MX=1, SX=1 @@ -502,7 +497,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=1 @@ -517,24 +512,21 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { 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 (auto & theTestVectorMsgExtension : theTestVectorMsgExtensions) + for (const auto & testEntry : theTestVectorMsgExtensions) { - testEntry = &theTestVectorMsgExtension; - - 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 f65900040aee54..9bcf0d25c7cbbb 100644 --- a/src/transport/tests/TestCryptoContext.cpp +++ b/src/transport/tests/TestCryptoContext.cpp @@ -50,15 +50,15 @@ struct PrivacyNonceTestEntry thePrivacyNonceTestVector[] = { void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext) { - for (auto & i : thePrivacyNonceTestVector) + for (const auto & testVector : thePrivacyNonceTestVector) { MessageAuthenticationCode mic; - uint16_t sessionId = i.sessionId; - const ByteSpan expectedPrivacyNonce(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, 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)); From 6b33974b5e1193b7235d582f50b05747037d984b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 3 Nov 2022 10:48:19 -0400 Subject: [PATCH 09/11] Restyle --- src/controller/tests/TestWriteChunking.cpp | 10 ++++----- src/crypto/tests/CHIPCryptoPALTest.cpp | 22 +++++++++---------- src/transport/raw/MessageHeader.h | 2 +- src/transport/raw/tests/TestMessageHeader.cpp | 16 +++++++------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/controller/tests/TestWriteChunking.cpp b/src/controller/tests/TestWriteChunking.cpp index c27b53b56cc099..726e73fe33eb19 100644 --- a/src/controller/tests/TestWriteChunking.cpp +++ b/src/controller/tests/TestWriteChunking.cpp @@ -634,7 +634,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute2) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute2) }, .expectedStatus = { true, true }, }); @@ -660,7 +660,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kNull, ListData::kList }, .expectedStatus = { true }, }); @@ -671,7 +671,7 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kList, ListData::kNull }, .expectedStatus = { true }, }); @@ -682,8 +682,8 @@ void TestWriteChunking::TestTransactionalList(nlTestSuite * apSuite, void * apCo RunTest(apSuite, ctx, Instructions{ .paths = { ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), - ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute), + ConcreteAttributePath(kTestEndpointId, Clusters::TestCluster::Id, kTestListAttribute) }, .data = { ListData::kList, ListData::kNull, ListData::kList }, .expectedStatus = { true }, }); diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index f3396012b33305..739215b34e5f4c 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -193,13 +193,13 @@ const AesCtrTestEntry theAesCtrTestVector[] = { .ciphertextLen = 16, }, { - .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", - .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", - .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", - .plaintextLen = 32, - .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" - "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", + .key = (const uint8_t *) "\x7e\x24\x06\x78\x17\xfa\xe0\xd7\x43\xd6\xce\x1f\x32\x53\x91\x63", + .nonce = (const uint8_t *) "\x00\x6c\xb6\xdb\xc0\x54\x3b\x59\xda\x48\xd9\x0b\x00", + .plaintext = (const uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + .plaintextLen = 32, + .ciphertext = (const uint8_t *) "\x4f\x3d\xf9\x49\x15\x88\x4d\xe0\xdc\x0e\x30\x95\x0d\xe7\xa6\xe9" + "\x5a\x91\x7e\x1d\x06\x42\x22\xdb\x2f\x6e\xc7\x3d\x99\x4a\xd9\x5f", .ciphertextLen = 32, } }; @@ -1333,8 +1333,8 @@ void TestCSR_GenDirect(nlTestSuite * inSuite, void * inContext) // Let's corrupt the CSR buffer and make sure it fails to verify size_t length = csrSpan.size(); - csrBuf[length - 2] = (uint8_t) (csrBuf[length - 2] + 1); - csrBuf[length - 1] = (uint8_t) (csrBuf[length - 1] + 1); + csrBuf[length - 2] = (uint8_t)(csrBuf[length - 2] + 1); + csrBuf[length - 1] = (uint8_t)(csrBuf[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csrSpan.data(), csrSpan.size(), pubkey) != CHIP_NO_ERROR); } @@ -1364,8 +1364,8 @@ static void TestCSR_GenByKeypair(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, memcmp(pubkey.ConstBytes(), keypair.Pubkey().ConstBytes(), pubkey.Length()) == 0); // Let's corrupt the CSR buffer and make sure it fails to verify - csr[length - 2] = (uint8_t) (csr[length - 2] + 1); - csr[length - 1] = (uint8_t) (csr[length - 1] + 1); + csr[length - 2] = (uint8_t)(csr[length - 2] + 1); + csr[length - 1] = (uint8_t)(csr[length - 1] + 1); NL_TEST_ASSERT(inSuite, VerifyCertificateSigningRequest(csr, length, pubkey) != CHIP_NO_ERROR); } diff --git a/src/transport/raw/MessageHeader.h b/src/transport/raw/MessageHeader.h index 4012faa57c8a59..b811cb17797b34 100644 --- a/src/transport/raw/MessageHeader.h +++ b/src/transport/raw/MessageHeader.h @@ -430,7 +430,7 @@ class PayloadHeader { public: constexpr PayloadHeader() { SetProtocol(Protocols::NotSpecified); } - constexpr PayloadHeader(const PayloadHeader &) = default; + constexpr PayloadHeader(const PayloadHeader &) = default; PayloadHeader & operator=(const PayloadHeader &) = default; /** Get the Session ID from this header. */ diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index eb10a7df3f630e..dc15dc894b0f49 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -430,7 +430,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test MX ================== { @@ -439,7 +439,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=none, MX=1, SX=0 @@ -447,7 +447,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + PRO_LEN + APP_LEN, .msg = "\x04\x00\x00\x20\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=none, DST=1, MX=1, SX=0 @@ -455,7 +455,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + DST_LEN + PRO_LEN + APP_LEN, .msg = "\x01\x00\x00\x20\xCC\xCC\xCC\xCC\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=0 @@ -472,7 +472,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x02\x00\x00\x21\xCC\xCC\xCC\xCC\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, { // SRC=1, DST=group, MX=1, SX=0 @@ -480,7 +480,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN, .msgLength = HDR_LEN + MX_LEN + SRC_LEN + GID_LEN + PRO_LEN + APP_LEN, .msg = "\x06\x00\x00\x21\xCC\xCC\xCC\xCC\x11\x11\x11\x11\x11\x11\x11\x11\xDD\xDD\x04\x00\xE4\xE3\xE2\xE1" - "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", + "\x01\xCC\xEE\xEE\x66\x66\xBB\xBB", }, // ================== Test SX ================== { @@ -489,7 +489,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x00\xCC\xCC\xCC\xCC" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=none, DST=none, MX=1, SX=1 @@ -497,7 +497,7 @@ struct TestVectorMsgExtensions theTestVectorMsgExtensions[] = { .appPayloadOffset = PRO_LEN + SX_LEN, .msgLength = HDR_LEN + MX_LEN + PRO_LEN + SX_LEN + APP_LEN, .msg = "\x00\x00\x00\x20\xCC\xCC\xCC\xCC\x04\x00\xE4\xE3\xE2\xE1" - "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", + "\x08\xCC\xEE\xEE\x66\x66\x04\x00\xE4\xE3\xE2\xE1\xBB\xBB", }, { // SRC=1, DST=1, MX=1, SX=1 From 19af31d8b17b3b58ef6c7837be15abf4df7c0e2d Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 3 Nov 2022 10:51:14 -0400 Subject: [PATCH 10/11] Enforce lowercase naming for cdSigningKey iterator variable --- .../DefaultDeviceAttestationVerifier.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp b/src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.cpp index 6c2cad430b63a6..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 (auto & CdSigningKey : gCdSigningKeys) + for (auto & cdSigningKey : gCdSigningKeys) { - if (kid.data_equal(CdSigningKey.mKid)) + if (kid.data_equal(cdSigningKey.mKid)) { - outPubKey = CdSigningKey.mPubkey; + outPubKey = cdSigningKey.mPubkey; return CHIP_NO_ERROR; } } From b9e634974104409c6aa7594b3f2ba96346c2da44 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 3 Nov 2022 15:31:33 -0400 Subject: [PATCH 11/11] One more pass for cleanups --- src/app/BufferedReadCallback.cpp | 4 ++-- src/app/tests/TestPendingNotificationMap.cpp | 2 +- src/lib/asn1/ASN1OID.cpp | 6 +++--- src/lib/dnssd/tests/TestTxtFields.cpp | 2 +- src/system/tests/TestSystemPacketBuffer.cpp | 2 +- src/transport/tests/TestSessionManager.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 28b38fe5366a41..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 (const auto & list : mBufferedList) + for (const auto & packetBuffer : mBufferedList) { - totalBufSize += list->TotalLength(); + totalBufSize += packetBuffer->TotalLength(); } // diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp index e8facbb1dc65b2..990bc0c8fa55d4 100644 --- a/src/app/tests/TestPendingNotificationMap.cpp +++ b/src/app/tests/TestPendingNotificationMap.cpp @@ -80,7 +80,7 @@ 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 (unsigned char ch : expectedEntryIndecies) + for (uint8_t ch : expectedEntryIndecies) { PendingNotificationEntry entry = *iter; NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == ch); diff --git a/src/lib/asn1/ASN1OID.cpp b/src/lib/asn1/ASN1OID.cpp index 5e43dff9c97a1e..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 (const auto & oid : sOIDTable) + for (const auto & tableEntry : sOIDTable) { - if (encodedOIDLen == oid.EncodedOIDLen && memcmp(encodedOID, oid.EncodedOID, encodedOIDLen) == 0) + if (encodedOIDLen == tableEntry.EncodedOIDLen && memcmp(encodedOID, tableEntry.EncodedOID, encodedOIDLen) == 0) { - return oid.EnumVal; + return tableEntry.EnumVal; } } diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 87d1e16e0ec4a0..f35ebf3183ae49 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -293,7 +293,7 @@ bool NodeDataIsEmpty(const DiscoveredNodeData & node) { return false; } - for (unsigned char id : node.commissionData.rotatingId) + for (uint8_t id : node.commissionData.rotatingId) { if (id != 0) { diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index a3c082cb12d889..cc462769d7f9dd 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -1817,7 +1817,7 @@ void PacketBufferTest::CheckHandleCloneData(nlTestSuite * inSuite, void * inCont NL_TEST_ASSERT(inSuite, test->mContext == theContext); uint8_t lPayload[2 * PacketBuffer::kMaxSizeWithoutReserve]; - for (unsigned char & payload : lPayload) + for (uint8_t & payload : lPayload) { payload = static_cast(random()); } diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index a1e2128f2624df..fcc4d7621b3af9 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -816,7 +816,7 @@ void SessionAllocationTest(nlTestSuite * inSuite, void * inContext) ScopedNodeId(NodeIdFromPAKEKeyId(kDefaultCommissioningPasscodeId), kUndefinedFabricIndex)); NL_TEST_ASSERT(inSuite, handle.HasValue()); auto potentialCollision = handle.Value()->AsSecureSession()->GetLocalSessionId(); - for (unsigned short sessionId : sessionIds) + for (uint16_t sessionId : sessionIds) { NL_TEST_ASSERT(inSuite, potentialCollision != sessionId); }