[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.
This commit is contained in:
Abtin Keshavarzian
2021-02-02 21:14:06 -08:00
committed by GitHub
parent ced158e65a
commit 4755eea1d1
2 changed files with 3 additions and 4 deletions
+2 -2
View File
@@ -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);
+1 -2
View File
@@ -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