From fbb1fbd1388a915912b188ae2a5a2a846b7e894e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 9 Jan 2019 10:01:17 +0100 Subject: [PATCH] [apps/code] Handle nullptr prompt text in input --- apps/code/console_controller.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 5ba4dc506..a316aab68 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -92,20 +92,23 @@ const char * ConsoleController::inputText(const char * prompt) { m_inputRunLoopActive = true; const char * promptText = prompt; - /* Set the prompt text. If the prompt text has a '\n', put the prompt text in - * the history until the last '\n', and put the remaining prompt text in the - * edit cell's prompt. */ - char * lastCarriageReturn = nullptr; char * s = const_cast(prompt); - while (*s != 0) { - if (*s == '\n') { - lastCarriageReturn = s; + + if (promptText != nullptr) { + /* Set the prompt text. If the prompt text has a '\n', put the prompt text in + * the history until the last '\n', and put the remaining prompt text in the + * edit cell's prompt. */ + char * lastCarriageReturn = nullptr; + while (*s != 0) { + if (*s == '\n') { + lastCarriageReturn = s; + } + s++; + } + if (lastCarriageReturn != nullptr) { + printText(prompt, lastCarriageReturn-prompt+1); + promptText = lastCarriageReturn+1; } - s++; - } - if (lastCarriageReturn != nullptr) { - printText(prompt, lastCarriageReturn-prompt+1); - promptText = lastCarriageReturn+1; } m_editCell.setPrompt(promptText); @@ -123,7 +126,9 @@ const char * ConsoleController::inputText(const char * prompt) { }, this); // Handle the input text - printText(promptText, s - promptText); + if (promptText != nullptr) { + printText(promptText, s - promptText); + } const char * text = m_editCell.text(); printText(text, strlen(text)); flushOutputAccumulationBufferToStore();