From de9edb01697522ec157e0d971ec245e4610bf806 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Jun 2019 19:22:58 +0200 Subject: [PATCH] StringView: operator==(const char*) needs to stop when the view ends. We were comparing past the end of the view, which was clearly not correct. --- AK/StringView.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AK/StringView.h b/AK/StringView.h index 8e5b31127d..c5a0b1a7a1 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -38,8 +38,17 @@ public: Vector split_view(char) const; unsigned to_uint(bool& ok) const; - bool operator==(const char* cstring) const { return !strcmp(m_characters, cstring); } - bool operator!=(const char* cstring) const { return strcmp(m_characters, cstring); } + bool operator==(const char* cstring) const + { + int other_length = strlen(cstring); + if (m_length != other_length) + return false; + return !memcmp(m_characters, cstring, m_length); + } + bool operator!=(const char* cstring) const + { + return !(*this == cstring); + } bool operator==(const String&) const;