[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:
Jonathan Hui
2020-02-11 07:12:51 -08:00
parent a84fea58e1
commit e9261b6842
4 changed files with 9 additions and 6 deletions
+3
View File
@@ -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);
+3 -3
View File
@@ -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.
+2 -2
View File
@@ -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));
+1 -1
View File
@@ -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());