diff --git a/src/core/common/settings.cpp b/src/core/common/settings.cpp index 7315af1fa..44491d823 100644 --- a/src/core/common/settings.cpp +++ b/src/core/common/settings.cpp @@ -252,7 +252,7 @@ otError Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo) uint16_t length = sizeof(prevNetworkInfo); if ((Read(kKeyNetworkInfo, &prevNetworkInfo, length) == OT_ERROR_NONE) && (length == sizeof(NetworkInfo)) && - (memcmp(&prevNetworkInfo, &aNetworkInfo, sizeof(NetworkInfo)) == 0)) + (prevNetworkInfo == aNetworkInfo)) { LogNetworkInfo("Re-saved", aNetworkInfo); ExitNow(); @@ -298,7 +298,7 @@ otError Settings::SaveParentInfo(const ParentInfo &aParentInfo) uint16_t length = sizeof(ParentInfo); if ((Read(kKeyParentInfo, &prevParentInfo, length) == OT_ERROR_NONE) && (length == sizeof(ParentInfo)) && - (memcmp(&prevParentInfo, &aParentInfo, sizeof(ParentInfo)) == 0)) + (prevParentInfo == aParentInfo)) { LogParentInfo("Re-saved", aParentInfo); ExitNow(); @@ -413,7 +413,7 @@ otError Settings::SaveDadInfo(const DadInfo &aDadInfo) uint16_t length = sizeof(DadInfo); if ((Read(kKeyDadInfo, &prevDadInfo, length) == OT_ERROR_NONE) && (length == sizeof(DadInfo)) && - (memcmp(&prevDadInfo, &aDadInfo, sizeof(DadInfo)) == 0)) + (prevDadInfo == aDadInfo)) { LogDadInfo("Re-saved", aDadInfo); ExitNow(); diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index b1819c581..c96ab9e8b 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -36,7 +36,9 @@ #include "openthread-core-config.h" +#include "common/clearable.hpp" #include "common/encoding.hpp" +#include "common/equatable.hpp" #include "common/locator.hpp" #include "common/non_copyable.hpp" #include "mac/mac_types.hpp" @@ -183,16 +185,16 @@ public: * */ OT_TOOL_PACKED_BEGIN - class NetworkInfo + class NetworkInfo : public Equatable, private Clearable { public: /** - * This method clears the struct object (setting all the fields to zero). + * This method initializes the `NetworkInfo` object. * */ void Init(void) { - memset(this, 0, sizeof(*this)); + Clear(); SetVersion(OT_THREAD_VERSION_1_1); } @@ -383,16 +385,16 @@ public: * */ OT_TOOL_PACKED_BEGIN - class ParentInfo + class ParentInfo : public Equatable, private Clearable { public: /** - * This method clears the struct object (setting all the fields to zero). + * This method initializes the `ParentInfo` object. * */ void Init(void) { - memset(this, 0, sizeof(*this)); + Clear(); SetVersion(OT_THREAD_VERSION_1_1); } @@ -544,14 +546,14 @@ public: * */ OT_TOOL_PACKED_BEGIN - class DadInfo + class DadInfo : public Equatable, private Clearable { public: /** - * This method clears the struct object (setting all the fields to zero). + * This method initializes the `DadInfo` object. * */ - void Init(void) { memset(this, 0, sizeof(*this)); } + void Init(void) { Clear(); } /** * This method returns the Dad Counter.