From c21766760b793464b0c54bbd600a8bb3ca0a3ca1 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 13 Dec 2022 22:45:51 +0200 Subject: [PATCH] Add strlen comparing back to StringView since it is not nullterminated --- BAN/BAN/String.cpp | 4 +++- BAN/BAN/StringView.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BAN/BAN/String.cpp b/BAN/BAN/String.cpp index 6b49b9d50..cefbeb30f 100644 --- a/BAN/BAN/String.cpp +++ b/BAN/BAN/String.cpp @@ -141,7 +141,9 @@ namespace BAN bool String::operator==(const char* other) const { - return memcmp(m_data, other, m_size + 1) == 0; + if (m_size != strlen(other)) + return false; + return memcmp(m_data, other, m_size) == 0; } ErrorOr String::Resize(size_type size, char ch) diff --git a/BAN/BAN/StringView.cpp b/BAN/BAN/StringView.cpp index 02c751d93..b86d78c73 100644 --- a/BAN/BAN/StringView.cpp +++ b/BAN/BAN/StringView.cpp @@ -45,7 +45,9 @@ namespace BAN bool StringView::operator==(const char* other) const { - return memcmp(m_data, other, m_size + 1) == 0; + if (m_size != strlen(other)) + return false; + return memcmp(m_data, other, m_size) == 0; } StringView StringView::Substring(size_type index, size_type len) const