From 4755eea1d1a02fc8c5610793815f182edf343615 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 2 Feb 2021 21:14:06 -0800 Subject: [PATCH] [cli] ensure to init `mInstance` before other member variables (#6132) This commit changes the order of member variable in `Cli` class ensuring `mInstance` is initialized before other member variables. This then allows the `mInstance` to be safely used from the constructor of other `Cli` sub-types. --- src/cli/cli.cpp | 4 ++-- src/cli/cli.hpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 6c91b25a1..471269b8b 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -111,7 +111,8 @@ constexpr Interpreter::Command Interpreter::sCommands[]; Interpreter *Interpreter::sInterpreter = nullptr; Interpreter::Interpreter(Instance *aInstance) - : mUserCommands(nullptr) + : mInstance(aInstance) + , mUserCommands(nullptr) , mUserCommandsLength(0) , mPingLength(kDefaultPingLength) , mPingCount(kDefaultPingCount) @@ -147,7 +148,6 @@ Interpreter::Interpreter(Instance *aInstance) #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE , mSrpServer(*this) #endif - , mInstance(aInstance) { #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE otThreadSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::HandleDiagnosticGetResponse, this); diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 0497f1d09..7c12afe1d 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -775,6 +775,7 @@ private: static_assert(Utils::LookupTable::IsSorted(sCommands), "Command Table is not sorted"); + Instance * mInstance; const otCliCommand *mUserCommands; uint8_t mUserCommandsLength; void * mUserCommandsContext; @@ -823,8 +824,6 @@ private: #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE SrpServer mSrpServer; #endif - - Instance *mInstance; }; } // namespace Cli