From 7f990b161b2e38d436f5ebc66c3e63f36af2d5ac Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 25 Jul 2023 17:25:18 +0200 Subject: [PATCH] libluna: Fix comparison of StringViews without null termination This regressed in de7e58c274, and made value arguments pretty much unusable. This really needs a test... --- libluna/src/StringView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libluna/src/StringView.cpp b/libluna/src/StringView.cpp index c8209675..00dbdb32 100644 --- a/libluna/src/StringView.cpp +++ b/libluna/src/StringView.cpp @@ -50,12 +50,14 @@ const char& StringView::operator[](usize index) const bool StringView::operator==(const char* other) const { - return !strcmp(m_string, other); + if (m_length != strlen(other)) return false; + return !strncmp(m_string, other, m_length); } bool StringView::operator==(StringView other) const { - return !strcmp(m_string, other.m_string); + if (m_length != other.m_length) return false; + return !strncmp(m_string, other.m_string, m_length); } Result> StringView::split(StringView delim) const