mirror of
https://github.com/espressif/openthread.git
synced 2026-08-27 20:39:54 +00:00
[settings] initialize structure before reading from storage (#4499)
This commit initializes the settings structures before reading. This helps prepare for a following commit that allows reading stored values that are shorter than expected. This commit also renames the Clear() methods to Init().
This commit is contained in:
@@ -143,6 +143,7 @@ otError Settings::ReadNetworkInfo(NetworkInfo &aNetworkInfo) const
|
||||
{
|
||||
otError error;
|
||||
|
||||
aNetworkInfo.Init();
|
||||
SuccessOrExit(error = ReadFixedSize(kKeyNetworkInfo, &aNetworkInfo, sizeof(NetworkInfo)));
|
||||
LogNetworkInfo("Read", aNetworkInfo);
|
||||
|
||||
@@ -186,6 +187,7 @@ otError Settings::ReadParentInfo(ParentInfo &aParentInfo) const
|
||||
{
|
||||
otError error;
|
||||
|
||||
aParentInfo.Init();
|
||||
SuccessOrExit(error = ReadFixedSize(kKeyParentInfo, &aParentInfo, sizeof(ParentInfo)));
|
||||
LogParentInfo("Read", aParentInfo);
|
||||
|
||||
@@ -291,6 +293,7 @@ void Settings::ChildInfoIterator::Read(void)
|
||||
uint16_t size = sizeof(ChildInfo);
|
||||
otError error;
|
||||
|
||||
mChildInfo.Init();
|
||||
SuccessOrExit(error = otPlatSettingsGet(&GetInstance(), kKeyChildInfo, mIndex,
|
||||
reinterpret_cast<uint8_t *>(&mChildInfo), &size));
|
||||
VerifyOrExit(size >= sizeof(ChildInfo), error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
*
|
||||
*/
|
||||
void Clear(void) { memset(this, 0, sizeof(*this)); }
|
||||
void Init(void) { memset(this, 0, sizeof(*this)); }
|
||||
|
||||
/**
|
||||
* This method returns the Thread role.
|
||||
@@ -271,7 +271,7 @@ public:
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
*
|
||||
*/
|
||||
void Clear(void) { memset(this, 0, sizeof(*this)); }
|
||||
void Init(void) { memset(this, 0, sizeof(*this)); }
|
||||
|
||||
/**
|
||||
* This method returns the extended address.
|
||||
@@ -305,7 +305,7 @@ public:
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
*
|
||||
*/
|
||||
void Clear(void) { memset(this, 0, sizeof(*this)); }
|
||||
void Init(void) { memset(this, 0, sizeof(*this)); }
|
||||
|
||||
/**
|
||||
* This method returns the extended address.
|
||||
|
||||
@@ -446,7 +446,7 @@ otError Mle::Store(void)
|
||||
otError error = OT_ERROR_NONE;
|
||||
Settings::NetworkInfo networkInfo;
|
||||
|
||||
networkInfo.Clear();
|
||||
networkInfo.Init();
|
||||
|
||||
if (IsAttached())
|
||||
{
|
||||
@@ -464,7 +464,7 @@ otError Mle::Store(void)
|
||||
{
|
||||
Settings::ParentInfo parentInfo;
|
||||
|
||||
parentInfo.Clear();
|
||||
parentInfo.Init();
|
||||
parentInfo.SetExtAddress(mParent.GetExtAddress());
|
||||
|
||||
SuccessOrExit(error = Get<Settings>().SaveParentInfo(parentInfo));
|
||||
|
||||
@@ -3617,7 +3617,7 @@ otError MleRouter::StoreChild(const Child &aChild)
|
||||
|
||||
IgnoreReturnValue(RemoveStoredChild(aChild.GetRloc16()));
|
||||
|
||||
childInfo.Clear();
|
||||
childInfo.Init();
|
||||
childInfo.SetExtAddress(aChild.GetExtAddress());
|
||||
childInfo.SetTimeout(aChild.GetTimeout());
|
||||
childInfo.SetRloc16(aChild.GetRloc16());
|
||||
|
||||
Reference in New Issue
Block a user