From 1157911ece96d327066b00337e8942386d47f764 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 7 Mar 2023 20:59:09 +0100 Subject: [PATCH] [shell/MainLoopDefault.cpp] Add a missing null check --- src/lib/shell/MainLoopDefault.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/shell/MainLoopDefault.cpp b/src/lib/shell/MainLoopDefault.cpp index fba29a7238f161..2492117483e852 100644 --- a/src/lib/shell/MainLoopDefault.cpp +++ b/src/lib/shell/MainLoopDefault.cpp @@ -196,6 +196,18 @@ void Engine::RunMainLoop() while (true) { char * line = static_cast(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).