From b9758ddaea341dcd274b380dc08dbc647cb900ae Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 8 Nov 2020 14:31:15 +0100 Subject: [PATCH] ProcessCompositeInput: ensure we dont cause UB on memcmp --- src/Console.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console.cpp b/src/Console.cpp index c517f66..26e47e6 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -129,7 +129,7 @@ static std::string CompositeInput; static bool CompositeInputExpected { false }; static void ProcessCompositeInput() { - if (memcmp(CompositeInput.data(), std::array { 91, 65 }.data(), 2) == 0) { + if (CompositeInput.size() == 2 && memcmp(CompositeInput.data(), std::array { 91, 65 }.data(), 2) == 0) { // UP ARROW if (!ConsoleHistory.empty()) { if (ConsoleHistoryReadIndex != 0) { @@ -137,7 +137,7 @@ static void ProcessCompositeInput() { } CInputBuff = ConsoleHistory.at(ConsoleHistoryReadIndex); } - } else if (memcmp(CompositeInput.data(), std::array { 91, 66 }.data(), 2) == 0) { + } else if (CompositeInput.size() == 2 && memcmp(CompositeInput.data(), std::array { 91, 66 }.data(), 2) == 0) { // DOWN ARROW if (!ConsoleHistory.empty()) { if (ConsoleHistoryReadIndex != ConsoleHistory.size() - 1) {