mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 06:52:05 +01:00
Fix ef71ce0a9d: Crash when user enters a blank line in the console. (#14711)
Crash caused by reading outside the bounds of string_view (though not the underlying buffer)
This commit is contained in:
@@ -453,7 +453,7 @@ void IConsoleClose()
|
||||
static std::optional<std::string_view> 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;
|
||||
|
||||
Reference in New Issue
Block a user