Skip to content

Commit

Permalink
[shell/MainLoopDefault.cpp] Add a missing null check
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Aug 9, 2023
1 parent bb0031f commit 1089386
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/shell/MainLoopDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ void Engine::RunMainLoop()
while (true)
{
char * line = static_cast<char *>(Platform::MemoryAlloc(CHIP_SHELL_MAX_LINE_SIZE));
if (line == nullptr)
{
CHIP_ERROR error = CHIP_ERROR_NO_MEMORY;
char errorStr[160];
bool errorStrFound = FormatCHIPError(errorStr, sizeof(errorStr), error);
if (!errorStrFound)
{
errorStr[0] = 0;
}
streamer_printf(streamer_get(), "Error: %s\r\n", errorStr);
}

if (ReadLine(line, CHIP_SHELL_MAX_LINE_SIZE) == 0u)
{
// Stop loop in case of empty read (Ctrl-D).
Expand Down

0 comments on commit 1089386

Please sign in to comment.