diff --git a/script/make-pretty b/script/make-pretty index 73c00532d..0483f7abc 100755 --- a/script/make-pretty +++ b/script/make-pretty @@ -135,6 +135,7 @@ readonly OT_CLANG_TIDY_CHECKS="\ google-explicit-constructor,\ google-readability-casting,\ misc-unused-using-decls,\ +modernize-loop-convert,\ modernize-use-bool-literals,\ modernize-use-equals-default,\ modernize-use-equals-delete,\ diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 3bd6f9c2d..1e7106f83 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -1028,10 +1028,8 @@ void Mac::BeginTransmit(void) // copy the frame into correct `TxFrame` for each radio type // (if it is not already prepared). - for (uint8_t index = 0; index < GetArrayLength(RadioTypes::kAllRadioTypes); index++) + for (RadioType radio : RadioTypes::kAllRadioTypes) { - RadioType radio = RadioTypes::kAllRadioTypes[index]; - if (txFrames.GetSelectedRadioTypes().Contains(radio)) { TxFrame &txFrame = txFrames.GetTxFrame(radio); @@ -1047,10 +1045,8 @@ void Mac::BeginTransmit(void) // process security for each radio type separately. This // allows radio links to handle security differently, e.g., // with different keys or link frame counters. - for (uint8_t index = 0; index < GetArrayLength(RadioTypes::kAllRadioTypes); index++) + for (RadioType radio : RadioTypes::kAllRadioTypes) { - RadioType radio = RadioTypes::kAllRadioTypes[index]; - if (txFrames.GetSelectedRadioTypes().Contains(radio)) { ProcessTransmitSecurity(txFrames.GetTxFrame(radio)); diff --git a/src/core/net/ip4_types.cpp b/src/core/net/ip4_types.cpp index 47e484196..4753eaf1b 100644 --- a/src/core/net/ip4_types.cpp +++ b/src/core/net/ip4_types.cpp @@ -111,14 +111,14 @@ void Address::ExtractFromIp6Address(uint8_t aPrefixLength, const Ip6::Address &a ip6Index = aPrefixLength / CHAR_BIT; - for (uint8_t i = 0; i < Ip4::Address::kSize; i++) + for (uint8_t &i : mFields.m8) { if (ip6Index == kSkipIndex) { ip6Index++; } - mFields.m8[i] = aIp6Address.GetBytes()[ip6Index++]; + i = aIp6Address.GetBytes()[ip6Index++]; } } diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index a7fbdb0ba..c244f5757 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -366,9 +366,9 @@ template <> otError NcpBase::HandlePropertyGet(void) } else { - for (size_t i = 0; i < sizeof(otIp6InterfaceIdentifier); i++) + for (uint8_t i : iid->mFields.m8) { - SuccessOrExit(error = mEncoder.WriteUint8(iid->mFields.m8[i])); + SuccessOrExit(error = mEncoder.WriteUint8(i)); } } @@ -388,9 +388,9 @@ template <> otError NcpBase::HandlePropertySet(void) { otIp6InterfaceIdentifier iid; - for (size_t i = 0; i < sizeof(otIp6InterfaceIdentifier); i++) + for (uint8_t &i : iid.mFields.m8) { - SuccessOrExit(error = mDecoder.ReadUint8(iid.mFields.m8[i])); + SuccessOrExit(error = mDecoder.ReadUint8(i)); } SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, &iid));