Compare commits

..

2 Commits

Author SHA1 Message Date
7f990b161b
libluna: Fix comparison of StringViews without null termination
All checks were successful
continuous-integration/drone/push Build is passing
This regressed in de7e58c274, and made value arguments pretty much unusable.

This really needs a test...
2023-07-25 17:25:18 +02:00
9bb3fed611
libluna: Use the right unsigned integer type for wcscmp()'s return type 2023-07-25 17:23:27 +02:00
2 changed files with 6 additions and 3 deletions

View File

@ -81,7 +81,8 @@ extern "C"
a++; a++;
b++; b++;
} }
return *(const u8*)a - *(const u8*)b; static_assert(sizeof(wchar_t) == sizeof(u32));
return *(const u32*)a - *(const u32*)b;
} }
int strncmp(const char* a, const char* b, usize max) int strncmp(const char* a, const char* b, usize max)

View File

@ -50,12 +50,14 @@ const char& StringView::operator[](usize index) const
bool StringView::operator==(const char* other) 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 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<Vector<String>> StringView::split(StringView delim) const Result<Vector<String>> StringView::split(StringView delim) const