mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[common] add GetArrayLength() and GetArrayEnd() (#7413)
This commit adds two inline template functions to get the length of an array and a pointer to the end of the array. These functions replace similar macros that were used with OT core modules. The template functions are safer to use since they would perform type checking at compile time. The functions validate that the input variable is indeed an array and unlike the macros they will not work with a pointer variable.
This commit is contained in:
committed by
GitHub
parent
49918c7f8e
commit
7ec658e47a
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
@@ -66,7 +67,7 @@ Error MulticastListenersTable::Add(const Ip6::Address &aAddress, Time aExpireTim
|
||||
}
|
||||
}
|
||||
|
||||
VerifyOrExit(mNumValidListeners < OT_ARRAY_LENGTH(mListeners), error = kErrorNoBufs);
|
||||
VerifyOrExit(mNumValidListeners < GetArrayLength(mListeners), error = kErrorNoBufs);
|
||||
|
||||
mListeners[mNumValidListeners].SetAddress(aAddress);
|
||||
mListeners[mNumValidListeners].SetExpireTime(aExpireTime);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
@@ -107,7 +108,7 @@ NdProxyTable::Iterator::Iterator(Instance &aInstance, NdProxyTable::Iterator::It
|
||||
: InstanceLocator(aInstance)
|
||||
{
|
||||
NdProxyTable &table = GetInstance().Get<BackboneRouter::NdProxyTable>();
|
||||
mItem = OT_ARRAY_END(table.mProxies);
|
||||
mItem = GetArrayEnd(table.mProxies);
|
||||
}
|
||||
|
||||
void NdProxyTable::Iterator::Advance(void)
|
||||
@@ -117,7 +118,7 @@ void NdProxyTable::Iterator::Advance(void)
|
||||
do
|
||||
{
|
||||
mItem++;
|
||||
} while (mItem < OT_ARRAY_END(table.mProxies) && !MatchesFilter(*mItem, mFilter));
|
||||
} while (mItem < GetArrayEnd(table.mProxies) && !MatchesFilter(*mItem, mFilter));
|
||||
}
|
||||
|
||||
void NdProxyTable::Erase(NdProxy &aNdProxy)
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "coap.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -1289,7 +1290,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
||||
*curUriPath++ = '/';
|
||||
}
|
||||
|
||||
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < OT_ARRAY_END(uriPath), error = kErrorParse);
|
||||
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < GetArrayEnd(uriPath), error = kErrorParse);
|
||||
|
||||
IgnoreError(iterator.ReadOptionValue(curUriPath));
|
||||
curUriPath += iterator.GetOption()->GetLength();
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "coap_message.hpp"
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -259,7 +260,7 @@ Error Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) con
|
||||
*curUriPath++ = '/';
|
||||
}
|
||||
|
||||
VerifyOrExit(curUriPath + optionLength < OT_ARRAY_END(aUriPath), error = kErrorParse);
|
||||
VerifyOrExit(curUriPath + optionLength < GetArrayEnd(aUriPath), error = kErrorParse);
|
||||
|
||||
IgnoreError(iterator.ReadOptionValue(curUriPath));
|
||||
curUriPath += optionLength;
|
||||
|
||||
@@ -44,6 +44,63 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
/**
|
||||
* This function returns the length of a given array (number of elements in the array).
|
||||
*
|
||||
* This template function is `constexpr`. The template arguments are expected to be deduced by the compiler allowing
|
||||
* callers to simply use `GetArrayLength(aArray)`.
|
||||
*
|
||||
* @tparam Type The array element type.
|
||||
* @tparam kLength The array length.
|
||||
*
|
||||
* @param[in] aArray A reference to the array.
|
||||
*
|
||||
* @returns The array length (number of elements in the array).
|
||||
*
|
||||
*/
|
||||
template <typename Type, uint16_t kArrayLength> constexpr inline uint16_t GetArrayLength(const Type (&)[kArrayLength])
|
||||
{
|
||||
return kArrayLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns a pointer to end of a given array (pointing to the past-the-end element).
|
||||
*
|
||||
* Note that the past-the-end element is a theoretical element that would follow the last element in the array. It does
|
||||
* not point to an actual element in array, and thus should not be dereferenced.
|
||||
*
|
||||
* @tparam Type The array element type.
|
||||
* @tparam kLength The array length.
|
||||
*
|
||||
* @param[in] aArray A reference to the array.
|
||||
*
|
||||
* @returns Pointer to the past-the-end element.
|
||||
*
|
||||
*/
|
||||
template <typename Type, uint16_t kArrayLength> inline Type *GetArrayEnd(Type (&aArray)[kArrayLength])
|
||||
{
|
||||
return &aArray[kArrayLength];
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns a pointer to end of a given array (pointing to the past-the-end element).
|
||||
*
|
||||
* Note that the past-the-end element is a theoretical element that would follow the last element in the array. It does
|
||||
* not point to an actual element in array, and thus should not be dereferenced.
|
||||
*
|
||||
* @tparam Type The array element type.
|
||||
* @tparam kLength The array length.
|
||||
*
|
||||
* @param[in] aArray A reference to the array.
|
||||
*
|
||||
* @returns Pointer to the past-the-end element.
|
||||
*
|
||||
*/
|
||||
template <typename Type, uint16_t kArrayLength> inline const Type *GetArrayEnd(const Type (&aArray)[kArrayLength])
|
||||
{
|
||||
return &aArray[kArrayLength];
|
||||
}
|
||||
|
||||
/**
|
||||
* This template class represents an array of elements with a fixed max size.
|
||||
*
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -80,7 +81,7 @@ const char *ErrorToString(Error aError)
|
||||
"Rejected", // (37) kErrorRejected
|
||||
};
|
||||
|
||||
return aError < OT_ARRAY_LENGTH(kErrorStrings) ? kErrorStrings[aError] : "UnknownErrorType";
|
||||
return aError < GetArrayLength(kErrorStrings) ? kErrorStrings[aError] : "UnknownErrorType";
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <openthread/platform/memory.h>
|
||||
#endif
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/error.hpp"
|
||||
#include "common/extension.hpp"
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "notifier.hpp"
|
||||
|
||||
#include "border_router/routing_manager.hpp"
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
@@ -289,7 +290,7 @@ const char *Notifier::EventToString(Event aEvent) const
|
||||
"PndDset", // kEventPendingDatasetChanged (1 << 29)
|
||||
};
|
||||
|
||||
for (uint8_t index = 0; index < OT_ARRAY_LENGTH(kEventStrings); index++)
|
||||
for (uint8_t index = 0; index < GetArrayLength(kEventStrings); index++)
|
||||
{
|
||||
if (static_cast<uint32_t>(aEvent) == (1U << index))
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/linked_list.hpp"
|
||||
#include "common/non_copyable.hpp"
|
||||
|
||||
@@ -147,7 +148,7 @@ public:
|
||||
* @retval FALSE if @p aObject is not from the pool.
|
||||
*
|
||||
*/
|
||||
bool IsPoolEntry(const Type &aObject) const { return (&mPool[0] <= &aObject) && (&aObject < OT_ARRAY_END(mPool)); }
|
||||
bool IsPoolEntry(const Type &aObject) const { return (&mPool[0] <= &aObject) && (&aObject < GetArrayEnd(mPool)); }
|
||||
|
||||
/**
|
||||
* This method returns the associated index of a given entry from the pool.
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "settings.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
@@ -195,7 +196,7 @@ const uint16_t Settings::kCriticalKeys[] = {
|
||||
void Settings::Init(void)
|
||||
{
|
||||
Get<SettingsDriver>().Init();
|
||||
Get<SettingsDriver>().SetCriticalKeys(kCriticalKeys, OT_ARRAY_LENGTH(kCriticalKeys));
|
||||
Get<SettingsDriver>().SetCriticalKeys(kCriticalKeys, GetArrayLength(kCriticalKeys));
|
||||
}
|
||||
|
||||
void Settings::Deinit(void)
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -1084,7 +1085,7 @@ 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 < OT_ARRAY_LENGTH(RadioTypes::kAllRadioTypes); index++)
|
||||
for (uint8_t index = 0; index < GetArrayLength(RadioTypes::kAllRadioTypes); index++)
|
||||
{
|
||||
RadioType radio = RadioTypes::kAllRadioTypes[index];
|
||||
|
||||
@@ -1103,7 +1104,7 @@ 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 < OT_ARRAY_LENGTH(RadioTypes::kAllRadioTypes); index++)
|
||||
for (uint8_t index = 0; index < GetArrayLength(RadioTypes::kAllRadioTypes); index++)
|
||||
{
|
||||
RadioType radio = RadioTypes::kAllRadioTypes[index];
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
|
||||
@@ -123,7 +124,7 @@ Error Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
|
||||
{
|
||||
Error error = kErrorNotFound;
|
||||
|
||||
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
|
||||
for (; aIterator < GetArrayLength(mFilterEntries); aIterator++)
|
||||
{
|
||||
const FilterEntry &entry = mFilterEntries[aIterator];
|
||||
|
||||
@@ -185,7 +186,7 @@ Error Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
|
||||
{
|
||||
Error error = kErrorNotFound;
|
||||
|
||||
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
|
||||
for (; aIterator < GetArrayLength(mFilterEntries); aIterator++)
|
||||
{
|
||||
FilterEntry &entry = mFilterEntries[aIterator];
|
||||
|
||||
@@ -200,7 +201,7 @@ Error Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
|
||||
}
|
||||
|
||||
// Return the default RssIn at the end of list
|
||||
if ((aIterator == OT_ARRAY_LENGTH(mFilterEntries)) && (mDefaultRssIn != kFixedRssDisabled))
|
||||
if ((aIterator == GetArrayLength(mFilterEntries)) && (mDefaultRssIn != kFixedRssDisabled))
|
||||
{
|
||||
AsCoreType(&aEntry.mExtAddress).Fill(0xff);
|
||||
aEntry.mRssIn = mDefaultRssIn;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/instance.hpp"
|
||||
@@ -516,7 +517,7 @@ Error Commissioner::GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoiner
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
while (aIterator < OT_ARRAY_LENGTH(mJoiners))
|
||||
while (aIterator < GetArrayLength(mJoiners))
|
||||
{
|
||||
const Joiner &joiner = mJoiners[aIterator++];
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -302,7 +303,7 @@ void Joiner::SaveDiscoveredJoinerRouter(const Mle::DiscoverScanner::ScanResult &
|
||||
{
|
||||
uint8_t priority;
|
||||
bool doesAllowAny;
|
||||
JoinerRouter *end = OT_ARRAY_END(mJoinerRouters);
|
||||
JoinerRouter *end = GetArrayEnd(mJoinerRouters);
|
||||
JoinerRouter *entry;
|
||||
|
||||
doesAllowAny = AsCoreType(&aResult.mSteeringData).PermitsAllJoiners();
|
||||
@@ -342,7 +343,7 @@ exit:
|
||||
|
||||
void Joiner::TryNextJoinerRouter(Error aPrevError)
|
||||
{
|
||||
for (; mJoinerRouterIndex < OT_ARRAY_LENGTH(mJoinerRouters); mJoinerRouterIndex++)
|
||||
for (; mJoinerRouterIndex < GetArrayLength(mJoinerRouters); mJoinerRouterIndex++)
|
||||
{
|
||||
JoinerRouter &router = mJoinerRouters[mJoinerRouterIndex];
|
||||
Error error;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -317,7 +318,7 @@ Error Server::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
VerifyOrExit(option.GetLength() == sizeof(option) - sizeof(Option), error = kErrorParse);
|
||||
|
||||
// mask matching prefix
|
||||
for (uint16_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (uint16_t i = 0; i < GetArrayLength(mPrefixAgents); i++)
|
||||
{
|
||||
if (mPrefixAgents[i].IsValid() && mPrefixAgents[i].IsPrefixMatch(option.GetAddress()))
|
||||
{
|
||||
@@ -397,7 +398,7 @@ Error Server::AppendIaNa(Message &aMessage, IaNa &aIaNa)
|
||||
|
||||
if (mPrefixAgentsMask)
|
||||
{
|
||||
for (uint16_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (uint16_t i = 0; i < GetArrayLength(mPrefixAgents); i++)
|
||||
{
|
||||
if (mPrefixAgentsMask & (1 << i))
|
||||
{
|
||||
@@ -437,7 +438,7 @@ Error Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClientId)
|
||||
if (mPrefixAgentsMask)
|
||||
{
|
||||
// if specified, only apply specified prefixes
|
||||
for (uint16_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (uint16_t i = 0; i < GetArrayLength(mPrefixAgents); i++)
|
||||
{
|
||||
if (mPrefixAgentsMask & (1 << i))
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -533,13 +534,13 @@ const uint16_t Client::kServiceQueryRecordTypes[] = {ResourceRecord::kTypeSrv, R
|
||||
#endif
|
||||
|
||||
const uint8_t Client::kQuestionCount[] = {
|
||||
/* kIp6AddressQuery -> */ OT_ARRAY_LENGTH(kIp6AddressQueryRecordTypes), // AAAA records
|
||||
/* kIp6AddressQuery -> */ GetArrayLength(kIp6AddressQueryRecordTypes), // AAAA records
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_NAT64_ENABLE
|
||||
/* kIp4AddressQuery -> */ OT_ARRAY_LENGTH(kIp4AddressQueryRecordTypes), // A records
|
||||
/* kIp4AddressQuery -> */ GetArrayLength(kIp4AddressQueryRecordTypes), // A records
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE
|
||||
/* kBrowseQuery -> */ OT_ARRAY_LENGTH(kBrowseQueryRecordTypes), // PTR records
|
||||
/* kServiceQuery -> */ OT_ARRAY_LENGTH(kServiceQueryRecordTypes), // SRV and TXT records
|
||||
/* kBrowseQuery -> */ GetArrayLength(kBrowseQueryRecordTypes), // PTR records
|
||||
/* kServiceQuery -> */ GetArrayLength(kServiceQueryRecordTypes), // SRV and TXT records
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -640,7 +641,7 @@ Error Dso::Connection::AppendPadding(Message &aMessage)
|
||||
// that its padded length is a multiple of the chosen block
|
||||
// length.
|
||||
|
||||
blockLength = kBlockLengths[Random::NonCrypto::GetUint8InRange(0, OT_ARRAY_LENGTH(kBlockLengths))];
|
||||
blockLength = kBlockLengths[Random::NonCrypto::GetUint8InRange(0, GetArrayLength(kBlockLengths))];
|
||||
|
||||
paddingTlv.Init((blockLength - ((aMessage.GetLength() + sizeof(Tlv)) % blockLength)) % blockLength);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -1022,7 +1023,7 @@ const otDnssdQuery *Server::GetNextQuery(const otDnssdQuery *aQuery) const
|
||||
cur = query + 1;
|
||||
}
|
||||
|
||||
for (; cur < OT_ARRAY_END(mQueryTransactions); cur++)
|
||||
for (; cur < GetArrayEnd(mQueryTransactions); cur++)
|
||||
{
|
||||
if (cur->IsValid())
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -613,7 +614,7 @@ Error Address::FromString(const char *aString)
|
||||
Ip4::Address ip4Addr;
|
||||
|
||||
SuccessOrExit(error = ip4Addr.FromString(aString));
|
||||
memcpy(OT_ARRAY_END(mFields.m8) - Ip4::Address::kSize, ip4Addr.GetBytes(), Ip4::Address::kSize);
|
||||
memcpy(GetArrayEnd(mFields.m8) - Ip4::Address::kSize, ip4Addr.GetBytes(), Ip4::Address::kSize);
|
||||
}
|
||||
|
||||
error = kErrorNone;
|
||||
@@ -639,7 +640,7 @@ void Address::ToString(char *aBuffer, uint16_t aSize) const
|
||||
|
||||
void Address::ToString(StringWriter &aWriter) const
|
||||
{
|
||||
AppendHexWords(aWriter, OT_ARRAY_LENGTH(mFields.m16));
|
||||
AppendHexWords(aWriter, static_cast<uint8_t>(GetArrayLength(mFields.m16)));
|
||||
}
|
||||
|
||||
void Address::AppendHexWords(StringWriter &aWriter, uint8_t aLength) const
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -148,7 +149,7 @@ void Interface::RegisterService(void)
|
||||
txtEntries[1].Init(kTxtRecordExtPanIdKey, Get<Mac::Mac>().GetExtendedPanId().m8, sizeof(Mac::ExtendedPanId));
|
||||
|
||||
txtData.Init(txtDataBuffer, sizeof(txtDataBuffer));
|
||||
SuccessOrAssert(Dns::TxtEntry::AppendEntries(txtEntries, OT_ARRAY_LENGTH(txtEntries), txtData));
|
||||
SuccessOrAssert(Dns::TxtEntry::AppendEntries(txtEntries, GetArrayLength(txtEntries), txtData));
|
||||
|
||||
otLogInfoMac("Trel: Registering DNS-SD service: port:%u, txt:\"%s=%s, %s=%s\"", mUdpPort, kTxtRecordExtAddressKey,
|
||||
Get<Mac::Mac>().GetExtAddress().ToString().AsCString(), kTxtRecordExtPanIdKey,
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <openthread/platform/radio.h>
|
||||
#include <openthread/platform/time.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -4522,7 +4523,7 @@ const char *Mle::RoleToString(DeviceRole aRole)
|
||||
static_assert(kRoleRouter == 3, "kRoleRouter value is incorrect");
|
||||
static_assert(kRoleLeader == 4, "kRoleLeader value is incorrect");
|
||||
|
||||
return (aRole < OT_ARRAY_LENGTH(kRoleStrings)) ? kRoleStrings[aRole] : "invalid";
|
||||
return (aRole < GetArrayLength(kRoleStrings)) ? kRoleStrings[aRole] : "invalid";
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/const_cast.hpp"
|
||||
#include "common/instance.hpp"
|
||||
@@ -184,7 +185,7 @@ const Publisher::PrefixEntry *Publisher::FindMatchingPrefixEntry(const Ip6::Pref
|
||||
|
||||
bool Publisher::IsAPrefixEntry(const Entry &aEntry) const
|
||||
{
|
||||
return (&mPrefixEntries[0] <= &aEntry) && (&aEntry < OT_ARRAY_END(mPrefixEntries));
|
||||
return (&mPrefixEntries[0] <= &aEntry) && (&aEntry < GetArrayEnd(mPrefixEntries));
|
||||
}
|
||||
|
||||
void Publisher::NotifyPrefixEntryChange(Event aEvent, const Ip6::Prefix &aPrefix) const
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -837,7 +838,7 @@ Error NetworkDiagnostic::GetNextDiagTlv(const Coap::Message &aMessage,
|
||||
ChildTableTlv &childTable = As<ChildTableTlv>(tlv);
|
||||
|
||||
VerifyOrExit(childTable.IsValid(), error = kErrorParse);
|
||||
VerifyOrExit(childTable.GetNumEntries() <= OT_ARRAY_LENGTH(aNetworkDiagTlv.mData.mChildTable.mTable),
|
||||
VerifyOrExit(childTable.GetNumEntries() <= GetArrayLength(aNetworkDiagTlv.mData.mChildTable.mTable),
|
||||
error = kErrorParse);
|
||||
|
||||
for (uint8_t i = 0; i < childTable.GetNumEntries(); ++i)
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "topology.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/instance.hpp"
|
||||
@@ -474,7 +475,7 @@ MlrState Child::GetAddressMlrState(const Ip6::Address &aAddress) const
|
||||
{
|
||||
uint16_t addressIndex;
|
||||
|
||||
OT_ASSERT(&mIp6Address[0] <= &aAddress && &aAddress < OT_ARRAY_END(mIp6Address));
|
||||
OT_ASSERT(&mIp6Address[0] <= &aAddress && &aAddress < GetArrayEnd(mIp6Address));
|
||||
|
||||
addressIndex = static_cast<uint16_t>(&aAddress - mIp6Address);
|
||||
|
||||
@@ -487,7 +488,7 @@ void Child::SetAddressMlrState(const Ip6::Address &aAddress, MlrState aState)
|
||||
{
|
||||
uint16_t addressIndex;
|
||||
|
||||
OT_ASSERT(&mIp6Address[0] <= &aAddress && &aAddress < OT_ARRAY_END(mIp6Address));
|
||||
OT_ASSERT(&mIp6Address[0] <= &aAddress && &aAddress < GetArrayEnd(mIp6Address));
|
||||
|
||||
addressIndex = static_cast<uint16_t>(&aAddress - mIp6Address);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
@@ -244,7 +245,7 @@ void Slaac::Update(UpdateMode aMode)
|
||||
if (!added)
|
||||
{
|
||||
otLogWarnUtil("SLAAC: Failed to add - max %d addresses supported and already in use",
|
||||
OT_ARRAY_LENGTH(mAddresses));
|
||||
GetArrayLength(mAddresses));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <openthread/srp_client_buffers.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/clearable.hpp"
|
||||
#include "common/locator.hpp"
|
||||
@@ -165,7 +166,7 @@ public:
|
||||
*/
|
||||
const char **GetSubTypeLabelsArray(uint16_t &aArrayLength)
|
||||
{
|
||||
aArrayLength = OT_ARRAY_LENGTH(mSubTypeLabels);
|
||||
aArrayLength = GetArrayLength(mSubTypeLabels);
|
||||
return mSubTypeLabels;
|
||||
}
|
||||
|
||||
@@ -213,7 +214,7 @@ public:
|
||||
*/
|
||||
Ip6::Address *GetHostAddressesArray(uint8_t &aArrayLength)
|
||||
{
|
||||
aArrayLength = OT_ARRAY_LENGTH(mHostAddresses);
|
||||
aArrayLength = static_cast<uint8_t>(GetArrayLength(mHostAddresses));
|
||||
return &mHostAddresses[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <openthread/error.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -242,7 +243,7 @@ public:
|
||||
{
|
||||
otError error = OT_ERROR_NO_BUFS;
|
||||
|
||||
if (GetFrame() + aLength <= OT_ARRAY_END(mBuffer))
|
||||
if (GetFrame() + aLength <= GetArrayEnd(mBuffer))
|
||||
{
|
||||
mWritePointer = GetFrame() + aLength;
|
||||
mRemainingLength = static_cast<uint16_t>(mBuffer + kSize - mWritePointer);
|
||||
@@ -273,7 +274,7 @@ public:
|
||||
{
|
||||
otError error = OT_ERROR_NO_BUFS;
|
||||
|
||||
if (mWriteFrameStart + kHeaderSize + aSkipLength <= OT_ARRAY_END(mBuffer))
|
||||
if (mWriteFrameStart + kHeaderSize + aSkipLength <= GetArrayEnd(mBuffer))
|
||||
{
|
||||
Encoding::LittleEndian::WriteUint16(aSkipLength, mWriteFrameStart + kHeaderSkipLengthOffset);
|
||||
mWritePointer = GetFrame();
|
||||
@@ -366,7 +367,7 @@ public:
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
OT_ASSERT(aFrame == nullptr || (mBuffer <= aFrame && aFrame < OT_ARRAY_END(mBuffer)));
|
||||
OT_ASSERT(aFrame == nullptr || (mBuffer <= aFrame && aFrame < GetArrayEnd(mBuffer)));
|
||||
|
||||
aFrame = (aFrame == nullptr) ? mBuffer : aFrame + aLength;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "test_util.h"
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "thread/child_table.hpp"
|
||||
@@ -290,7 +291,7 @@ void TestChildTable(void)
|
||||
},
|
||||
};
|
||||
|
||||
const uint16_t testListLength = OT_ARRAY_LENGTH(testChildList);
|
||||
const uint16_t testListLength = GetArrayLength(testChildList);
|
||||
|
||||
uint16_t testNumAllowedChildren = 2;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "net/dns_types.hpp"
|
||||
|
||||
@@ -1095,7 +1096,7 @@ void TestHeaderAndResourceRecords(void)
|
||||
printf("Use FindRecord() to search for specific records:\n");
|
||||
printf(" Answer Section\n");
|
||||
|
||||
for (index = 0; index < OT_ARRAY_LENGTH(kInstanceNames); index++)
|
||||
for (index = 0; index < GetArrayLength(kInstanceNames); index++)
|
||||
{
|
||||
offset = answerSectionOffset;
|
||||
SuccessOrQuit(
|
||||
@@ -1248,13 +1249,13 @@ void TestDnsTxtEntry(void)
|
||||
VerifyOrQuit((message = messagePool->Allocate(Message::kTypeIp6)) != nullptr);
|
||||
|
||||
data.Init(txtData, sizeof(txtData));
|
||||
SuccessOrQuit(Dns::TxtEntry::AppendEntries(kTxtEntries, OT_ARRAY_LENGTH(kTxtEntries), data));
|
||||
SuccessOrQuit(Dns::TxtEntry::AppendEntries(kTxtEntries, GetArrayLength(kTxtEntries), data));
|
||||
VerifyOrQuit(data.GetBytes() == txtData);
|
||||
txtDataLength = data.GetLength();
|
||||
VerifyOrQuit(txtDataLength < kMaxTxtDataSize, "TXT data is too long");
|
||||
DumpBuffer("txt data", txtData, txtDataLength);
|
||||
|
||||
SuccessOrQuit(Dns::TxtEntry::AppendEntries(kTxtEntries, OT_ARRAY_LENGTH(kTxtEntries), *message));
|
||||
SuccessOrQuit(Dns::TxtEntry::AppendEntries(kTxtEntries, GetArrayLength(kTxtEntries), *message));
|
||||
VerifyOrQuit(txtDataLength == message->GetLength());
|
||||
VerifyOrQuit(message->CompareBytes(0, txtData, txtDataLength));
|
||||
|
||||
|
||||
@@ -28,13 +28,14 @@
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "common/debug.hpp"
|
||||
#include "crypto/hkdf_sha256.hpp"
|
||||
|
||||
#include "test_platform.h"
|
||||
#include "test_util.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "crypto/hkdf_sha256.hpp"
|
||||
|
||||
struct TestVector
|
||||
{
|
||||
const uint8_t *mInKey;
|
||||
@@ -125,7 +126,7 @@ void TestHkdfSha256(void)
|
||||
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
|
||||
for (const TestVector *test = &kTestVectors[0]; test < OT_ARRAY_END(kTestVectors); test++)
|
||||
for (const TestVector *test = &kTestVectors[0]; test < ot::GetArrayEnd(kTestVectors); test++)
|
||||
{
|
||||
ot::Crypto::HkdfSha256 hkdf;
|
||||
uint8_t outKey[kMaxOuttKey];
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "crypto/hmac_sha256.hpp"
|
||||
@@ -87,7 +88,7 @@ void TestSha256(void)
|
||||
Instance * instance = testInitInstance();
|
||||
MessagePool *messagePool;
|
||||
Message * message;
|
||||
uint16_t offsets[OT_ARRAY_LENGTH(kTestCases)];
|
||||
uint16_t offsets[GetArrayLength(kTestCases)];
|
||||
uint8_t index;
|
||||
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
@@ -228,7 +229,7 @@ void TestHmacSha256(void)
|
||||
Instance * instance = testInitInstance();
|
||||
MessagePool *messagePool;
|
||||
Message * message;
|
||||
uint16_t offsets[OT_ARRAY_LENGTH(kTestCases)];
|
||||
uint16_t offsets[GetArrayLength(kTestCases)];
|
||||
uint8_t index;
|
||||
|
||||
printf("TestHmacSha256\n");
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "thread/link_quality.hpp"
|
||||
|
||||
#include "test_platform.h"
|
||||
#include "test_util.h"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "thread/link_quality.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
@@ -412,7 +413,7 @@ void TestSuccessRateTracker(void)
|
||||
|
||||
// Adding success/failure at different rates and checking the RateTracker rate for every sample
|
||||
|
||||
for (uint16_t testRound = 0; testRound < OT_ARRAY_LENGTH(kWeightLimit) * 2; testRound++)
|
||||
for (uint16_t testRound = 0; testRound < GetArrayLength(kWeightLimit) * 2; testRound++)
|
||||
{
|
||||
uint16_t weightLimit;
|
||||
bool reverseLogic;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "test_platform.h"
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/instance.hpp"
|
||||
@@ -585,7 +586,7 @@ template <typename TimerType> int TestTenTimers(void)
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < OT_ARRAY_LENGTH(kTimeShift); i++)
|
||||
for (i = 0; i < ot::GetArrayLength(kTimeShift); i++)
|
||||
{
|
||||
TenTimers<TimerType>(kTimeShift[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user