From bf4dae0c18dc84bb87091897d79d9b3d678fda66 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 8 Nov 2019 16:51:47 -0800 Subject: [PATCH] [settings] add Clear() method for all setting structures (#4315) --- src/core/common/settings.hpp | 18 ++++++++++++++++++ src/core/thread/mle.cpp | 4 ++-- src/core/thread/mle_router.cpp | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 4070a32c0..2f816ef99 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -86,6 +86,12 @@ public: */ struct NetworkInfo { + /** + * This method clears the struct object (setting all the fields to zero). + * + */ + void Clear(void) { memset(this, 0, sizeof(*this)); } + uint8_t mRole; ///< Current Thread role. uint8_t mDeviceMode; ///< Device mode setting. uint16_t mRloc16; ///< RLOC16 @@ -103,6 +109,12 @@ public: */ struct ParentInfo { + /** + * This method clears the struct object (setting all the fields to zero). + * + */ + void Clear(void) { memset(this, 0, sizeof(*this)); } + Mac::ExtAddress mExtAddress; ///< Extended Address }; @@ -112,6 +124,12 @@ public: */ struct ChildInfo { + /** + * This method clears the struct object (setting all the fields to zero). + * + */ + void Clear(void) { memset(this, 0, sizeof(*this)); } + Mac::ExtAddress mExtAddress; ///< Extended Address uint32_t mTimeout; ///< Timeout uint16_t mRloc16; ///< RLOC16 diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 10999f18a..5fad430c6 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -447,7 +447,7 @@ otError Mle::Store(void) otError error = OT_ERROR_NONE; Settings::NetworkInfo networkInfo; - memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.Clear(); if (IsAttached()) { @@ -465,7 +465,7 @@ otError Mle::Store(void) { Settings::ParentInfo parentInfo; - memset(&parentInfo, 0, sizeof(parentInfo)); + parentInfo.Clear(); parentInfo.mExtAddress = mParent.GetExtAddress(); SuccessOrExit(error = Get().SaveParentInfo(parentInfo)); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index a962228ae..9e1fe80f5 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -3571,7 +3571,7 @@ otError MleRouter::StoreChild(const Child &aChild) IgnoreReturnValue(RemoveStoredChild(aChild.GetRloc16())); - memset(&childInfo, 0, sizeof(childInfo)); + childInfo.Clear(); childInfo.mExtAddress = aChild.GetExtAddress(); childInfo.mTimeout = aChild.GetTimeout(); childInfo.mRloc16 = aChild.GetRloc16();