AK: Make Utf32View::substring_view() with 0 length not crash

Just make it hand out a zero-length Utf32View :^)
This commit is contained in:
Andreas Kling 2020-05-18 15:07:37 +02:00
parent 195c1784ba
commit 7207276697

View file

@ -34,6 +34,7 @@ namespace AK {
class Utf32View {
public:
Utf32View() { }
Utf32View(const u32* codepoints, size_t length)
: m_codepoints(codepoints)
, m_length(length)
@ -46,6 +47,8 @@ public:
Utf32View substring_view(size_t offset, size_t length) const
{
if (length == 0)
return {};
ASSERT(offset < m_length);
ASSERT(!Checked<size_t>::addition_would_overflow(offset, length));
ASSERT((offset + length) <= m_length);