[common] add ClearAllBytes() template function (#9818)

This commit introduces the `ClearAllBytes<ObjectType>()` template
function to zero out all bytes within an object. This replaces
`memset(0)` calls in OT core modules, simplifying code and improving
safety by automatically using the correct object size.
This commit is contained in:
Abtin Keshavarzian
2024-02-01 11:58:47 -08:00
committed by GitHub
parent fffb489b26
commit 686eb30e9a
45 changed files with 136 additions and 107 deletions
+5 -5
View File
@@ -526,7 +526,7 @@ otError Dataset::ProcessCommand(const ComponentMapper &aMapper, Arg aArgs[])
}
else
{
memset(&dataset, 0, sizeof(dataset));
ClearAllBytes(dataset);
SuccessOrExit(error = (this->*aMapper.mParse)(aArgs, dataset));
dataset.mComponents.*aMapper.mIsPresentPtr = true;
SuccessOrExit(error = otDatasetUpdateTlvs(&dataset, &sDatasetTlvs));
@@ -716,7 +716,7 @@ template <> otError Dataset::Process<Cmd("clear")>(Arg aArgs[])
{
OT_UNUSED_VARIABLE(aArgs);
memset(&sDatasetTlvs, 0, sizeof(sDatasetTlvs));
ClearAllBytes(sDatasetTlvs);
return OT_ERROR_NONE;
}
@@ -765,7 +765,7 @@ template <> otError Dataset::Process<Cmd("mgmtsetcommand")>(Arg aArgs[])
uint8_t tlvs[128];
uint8_t tlvsLength = 0;
memset(&dataset, 0, sizeof(dataset));
ClearAllBytes(dataset);
for (Arg *arg = &aArgs[1]; !arg->IsEmpty();)
{
@@ -853,7 +853,7 @@ template <> otError Dataset::Process<Cmd("mgmtgetcommand")>(Arg aArgs[])
bool destAddrSpecified = false;
otIp6Address address;
memset(&datasetComponents, 0, sizeof(datasetComponents));
ClearAllBytes(datasetComponents);
for (Arg *arg = &aArgs[1]; !arg->IsEmpty(); arg++)
{
@@ -1003,7 +1003,7 @@ otError Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, Arg *&aA
otSecurityPolicy policy;
uint8_t versionThreshold;
memset(&policy, 0, sizeof(policy));
ClearAllBytes(policy);
SuccessOrExit(error = aArgs->ParseAsUint16(policy.mRotationTime));
aArgs++;