diff --git a/src/console_gui.cpp b/src/console_gui.cpp index db8831f259..06db00510f 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -453,7 +453,7 @@ void IConsoleClose() static std::optional IConsoleHistoryAdd(std::string_view cmd) { /* Strip all spaces at the begin */ - while (IsWhitespace(cmd[0])) cmd.remove_prefix(1); + while (!cmd.empty() && IsWhitespace(cmd[0])) cmd.remove_prefix(1); /* Do not put empty command in history */ if (cmd.empty()) return std::nullopt;