1
0
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:
Peter Nelson
2025-10-15 23:16:00 +01:00
committed by GitHub
parent 8e055156e3
commit a949197264

View File

@@ -453,7 +453,7 @@ void IConsoleClose()
static std::optional<std::string_view> IConsoleHistoryAdd(std::string_view cmd) static std::optional<std::string_view> IConsoleHistoryAdd(std::string_view cmd)
{ {
/* Strip all spaces at the begin */ /* 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 */ /* Do not put empty command in history */
if (cmd.empty()) return std::nullopt; if (cmd.empty()) return std::nullopt;