diff --git a/.clang-tidy b/.clang-tidy index 50c4d9633..61af657f6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ Checks: > -*, bugprone-argument-comment, + bugprone-too-small-loop-variable, google-explicit-constructor, google-readability-casting, misc-unused-using-decls, diff --git a/examples/platforms/simulation/flash.c b/examples/platforms/simulation/flash.c index ce07f3a70..59461e0e9 100644 --- a/examples/platforms/simulation/flash.c +++ b/examples/platforms/simulation/flash.c @@ -84,7 +84,7 @@ void otPlatFlashInit(otInstance *aInstance) if (create) { - for (uint8_t index = 0; index < SWAP_NUM; index++) + for (uint8_t index = 0; index < (uint8_t)SWAP_NUM; index++) { otPlatFlashErase(aInstance, index); } diff --git a/examples/platforms/simulation/radio.c b/examples/platforms/simulation/radio.c index 9fe37b66c..6ba2a5dcf 100644 --- a/examples/platforms/simulation/radio.c +++ b/examples/platforms/simulation/radio.c @@ -236,7 +236,7 @@ otError ProcessNodeIdFilter(void *aContext, uint8_t aArgsLength, char *aArgs[]) break; } - for (uint16_t nodeId = 0; nodeId <= MAX_NETWORK_SIZE; nodeId++) + for (uint16_t nodeId = 0; nodeId <= (uint16_t)MAX_NETWORK_SIZE; nodeId++) { if (FilterContainsId(nodeId)) { diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index fcfee7b9d..b814d092b 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -5256,7 +5256,7 @@ void Interpreter::HandleMeshDiagDiscoverDone(otError aError, otMeshDiagRouterInf { OutputFormat(kIndentSize, "%u-links:{ ", linkQuality); - for (uint8_t id = 0; id < OT_ARRAY_LENGTH(aRouterInfo->mLinkQualities); id++) + for (uint8_t id = 0; id < static_cast(OT_ARRAY_LENGTH(aRouterInfo->mLinkQualities)); id++) { if (aRouterInfo->mLinkQualities[id] == linkQuality) { diff --git a/src/cli/cli_dns.cpp b/src/cli/cli_dns.cpp index 8d7e0a414..c532a0f6f 100644 --- a/src/cli/cli_dns.cpp +++ b/src/cli/cli_dns.cpp @@ -496,7 +496,7 @@ otError Dns::ParseDnsServiceMode(const Arg &aArg, otDnsServiceMode &aMode) const ExitNow(); } - for (uint8_t index = 0; index < OT_ARRAY_LENGTH(kServiceModeStrings); index++) + for (size_t index = 0; index < OT_ARRAY_LENGTH(kServiceModeStrings); index++) { if (aArg == kServiceModeStrings[index]) { diff --git a/src/cli/cli_mac_filter.cpp b/src/cli/cli_mac_filter.cpp index 6525a20aa..7201c0423 100644 --- a/src/cli/cli_mac_filter.cpp +++ b/src/cli/cli_mac_filter.cpp @@ -173,7 +173,7 @@ template <> otError MacFilter::Process(Arg aArgs[]) "denylist", // (2) OT_MAC_FILTER_ADDRESS_MODE_DENYLIST }; - for (uint8_t index = 0; index < OT_ARRAY_LENGTH(kModeCommands); index++) + for (size_t index = 0; index < OT_ARRAY_LENGTH(kModeCommands); index++) { if (aArgs[0] == kModeCommands[index]) { diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index 6fb17b020..9dd65663c 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -64,7 +64,7 @@ bool JoinerPskd::operator==(const JoinerPskd &aOther) const { bool isEqual = true; - for (uint8_t i = 0; i < sizeof(m8); i++) + for (size_t i = 0; i < sizeof(m8); i++) { if (m8[i] != aOther.m8[i]) { diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index be009f396..97926091d 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -340,7 +340,7 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) tlv.Init(); - for (uint8_t page = 0; page < sizeof(Radio::kSupportedChannelPages) * CHAR_BIT; page++) + for (uint8_t page = 0; page < static_cast(sizeof(Radio::kSupportedChannelPages) * CHAR_BIT); page++) { if (Radio::kSupportedChannelPages & (1 << page)) { diff --git a/tests/unit/test_cmd_line_parser.cpp b/tests/unit/test_cmd_line_parser.cpp index 7f832cf11..cc2a93595 100644 --- a/tests/unit/test_cmd_line_parser.cpp +++ b/tests/unit/test_cmd_line_parser.cpp @@ -309,7 +309,7 @@ void TestParsingHexStrings(void) for (uint8_t testIter = 0; testIter <= 1; testIter++) { - for (uint8_t segmentLen = 1; segmentLen <= sizeof(buffer); segmentLen++) + for (size_t segmentLen = 1; segmentLen <= sizeof(buffer); segmentLen++) { if (testIter == 0) { @@ -324,7 +324,7 @@ void TestParsingHexStrings(void) len = segmentLen; - printf("\"%s\" segLen:%d -> ", string, segmentLen); + printf("\"%s\" segLen:%zu -> ", string, segmentLen); while (true) { diff --git a/tests/unit/test_hkdf_sha256.cpp b/tests/unit/test_hkdf_sha256.cpp index a50ac8488..019db5690 100644 --- a/tests/unit/test_hkdf_sha256.cpp +++ b/tests/unit/test_hkdf_sha256.cpp @@ -150,7 +150,7 @@ void TestHkdfSha256(void) VerifyOrQuit(memcmp(outKey, test->mOutKey, test->mOutKeyLength) == 0, "HKDF-SHA-256 failed"); - for (uint16_t i = test->mOutKeyLength + 1; i < sizeof(outKey); i++) + for (size_t i = test->mOutKeyLength + 1; i < sizeof(outKey); i++) { VerifyOrQuit(outKey[i] == kFillByte, "HKDF-SHA-256 wrote beyond output key length"); } diff --git a/tests/unit/test_ip_address.cpp b/tests/unit/test_ip_address.cpp index 153a2c13a..a3b71cf42 100644 --- a/tests/unit/test_ip_address.cpp +++ b/tests/unit/test_ip_address.cpp @@ -366,7 +366,7 @@ bool CheckInterfaceId(const ot::Ip6::Address &aAddress1, const ot::Ip6::Address bool matches = true; - for (uint8_t bit = aPrefixLength; bit < sizeof(ot::Ip6::Address) * CHAR_BIT; bit++) + for (size_t bit = aPrefixLength; bit < sizeof(ot::Ip6::Address) * CHAR_BIT; bit++) { uint8_t index = bit / CHAR_BIT; uint8_t mask = (0x80 >> (bit % CHAR_BIT)); @@ -403,14 +403,14 @@ void TestIp6AddressSetPrefix(void) memcpy(address.mFields.m8, prefix, sizeof(address)); printf("Prefix is %s\n", address.ToString().AsCString()); - for (uint8_t prefixLength = 0; prefixLength <= sizeof(ot::Ip6::Address) * CHAR_BIT; prefixLength++) + for (size_t prefixLength = 0; prefixLength <= sizeof(ot::Ip6::Address) * CHAR_BIT; prefixLength++) { ip6Prefix.Clear(); ip6Prefix.Set(prefix, prefixLength); address = allZeroAddress; address.SetPrefix(ip6Prefix); - printf(" prefix-len:%-3d --> %s\n", prefixLength, address.ToString().AsCString()); + printf(" prefix-len:%-3zu --> %s\n", prefixLength, address.ToString().AsCString()); VerifyOrQuit(CheckPrefix(address, prefix, prefixLength), "Prefix does not match after SetPrefix()"); VerifyOrQuit(CheckInterfaceId(address, allZeroAddress, prefixLength), "SetPrefix changed bits beyond the prefix length"); diff --git a/tests/unit/test_mac_frame.cpp b/tests/unit/test_mac_frame.cpp index 7966b70e9..b92003f8c 100644 --- a/tests/unit/test_mac_frame.cpp +++ b/tests/unit/test_mac_frame.cpp @@ -442,7 +442,7 @@ void TestMacChannelMask(void) VerifyChannelMaskContent(mask1, allChannels, sizeof(allChannels)); // Test ChannelMask::RemoveChannel() - for (uint8_t index = 0; index < sizeof(allChannels) - 1; index++) + for (size_t index = 0; index < sizeof(allChannels) - 1; index++) { mask1.RemoveChannel(allChannels[index]); VerifyChannelMaskContent(mask1, &allChannels[index + 1], sizeof(allChannels) - 1 - index); diff --git a/tests/unit/test_nat64.cpp b/tests/unit/test_nat64.cpp index 66e5fbeb1..d699d83f8 100644 --- a/tests/unit/test_nat64.cpp +++ b/tests/unit/test_nat64.cpp @@ -50,7 +50,7 @@ void DumpMessageInHex(const char *prefix, const uint8_t *aBuf, size_t aBufLen) { // This function dumps all packets the output of this function can be imported to packet analyser for debugging. printf("%s", prefix); - for (uint16_t i = 0; i < aBufLen; i++) + for (size_t i = 0; i < aBufLen; i++) { printf("%02x", aBuf[i]); } @@ -71,7 +71,7 @@ bool CheckMessage(const Message &aMessage, const uint8_t *aExpectedMessage, size if (!success) { printf("Expected Message\n"); - for (uint16_t i = 0; i < aExpectedMessageLen; i++) + for (size_t i = 0; i < aExpectedMessageLen; i++) { printf("%02x%c", aExpectedMessage[i], " \n"[(i & 0xf) == 0xf]); } diff --git a/tests/unit/test_toolchain.cpp b/tests/unit/test_toolchain.cpp index 643b502fe..def163462 100644 --- a/tests/unit/test_toolchain.cpp +++ b/tests/unit/test_toolchain.cpp @@ -132,7 +132,7 @@ void test_packed_alignment(void) packedStruct.mByte = 0xfe; packedStruct.mUint16 = 0xabcd; - for (uint16_t start = 0; start < sizeof(PackedStruct); start++) + for (size_t start = 0; start < sizeof(PackedStruct); start++) { uint8_t *ptr = &buffer[start]; @@ -140,14 +140,14 @@ void test_packed_alignment(void) *reinterpret_cast(ptr) = packedStruct; - for (uint16_t i = 0; i < start; i++) + for (size_t i = 0; i < start; i++) { VerifyOrQuit(buffer[i] == 0, "OT_TOOL_PACKED alignment failed - pre-size write"); } VerifyOrQuit(memcmp(ptr, packedStructBytes, sizeof(PackedStruct)) == 0, "OT_TOOL_PACKED alignment failed"); - for (uint16_t i = start + sizeof(packedStruct); i < sizeof(buffer); i++) + for (size_t i = start + sizeof(packedStruct); i < sizeof(buffer); i++) { VerifyOrQuit(buffer[i] == 0, "OT_TOOL_PACKED alignment failed - post-size write"); }