AK: Allow creating a StringView from an empty ReadonlyBytes

An empty Span (and so ReadonlyBytes) can be created with a null data
pointer, which is no longer allowed for StringView. Detect that case
and use an empty string instead.
This commit is contained in:
Sam Atkins
2026-03-31 16:02:55 +01:00
committed by Shannon Booth
parent 5a7ef7d494
commit 7781f1d131
Notes: github-actions[bot] 2026-03-31 17:02:18 +00:00

View File

@@ -43,10 +43,9 @@ public:
}
ALWAYS_INLINE StringView(ReadonlyBytes bytes)
: m_characters(reinterpret_cast<char const*>(bytes.data()))
: m_characters(bytes.is_empty() ? "" : reinterpret_cast<char const*>(bytes.data()))
, m_length(bytes.size())
{
VERIFY(bytes.data() != nullptr);
}
StringView(LIFETIME_BOUND ByteBuffer const&);