[cli] fix crash when full logs is on (#5408)

It is possible that log is printed before the Interpreter (UART or
CONSOLE) object is created when FULL LOGS is enabled. In such case, OT
crashes. This commit fixes this bug.
This commit is contained in:
Simon Lin
2020-08-18 23:43:12 +08:00
committed by GitHub
parent 962c06f8e7
commit 54b31928cf
4 changed files with 26 additions and 18 deletions
+6
View File
@@ -251,6 +251,8 @@ const struct Command Interpreter::sCommands[] = {
{"version", &Interpreter::ProcessVersion},
};
Interpreter *Interpreter::sInterpreter = nullptr;
Interpreter::Interpreter(Instance *aInstance)
: mUserCommands(nullptr)
, mUserCommandsLength(0)
@@ -4679,8 +4681,12 @@ extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, cons
OT_UNUSED_VARIABLE(aLogLevel);
OT_UNUSED_VARIABLE(aLogRegion);
VerifyOrExit(Interpreter::IsInitialized(), OT_NOOP);
Interpreter::GetInterpreter().OutputFormatV(aFormat, aArgs);
Interpreter::GetInterpreter().OutputFormat("\r\n");
exit:
return;
}
} // namespace Cli