From 53b85bcdd0447b64fde9ab9b5197d64f175d63ae Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 14 Sep 2020 19:31:47 +0430 Subject: [PATCH] Shell: Make Parser::expect() revert the offset when matching fails --- Shell/Parser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index 3b101619e8..ee9589b0a3 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -58,12 +58,16 @@ bool Parser::expect(char ch) bool Parser::expect(const StringView& expected) { + auto offset_at_start = m_offset; + if (expected.length() + m_offset > m_input.length()) return false; for (size_t i = 0; i < expected.length(); ++i) { - if (peek() != expected[i]) + if (peek() != expected[i]) { + m_offset = offset_at_start; return false; + } consume(); }