AK: VERIFY() the index is in bounds in StringView::operator[]

That this did not already happen took me by surprise, as for
most other similar containers/types in AK (e.g. Span) the index
will be checked. This check not happening could easily let
off-by-one indexing errors slip through the cracks.
This commit is contained in:
MacDue 2022-07-26 00:38:49 +01:00 committed by Andreas Kling
parent 5f34c8ab03
commit 13406b83b1

View file

@ -62,7 +62,12 @@ public:
[[nodiscard]] ReadonlyBytes bytes() const { return { m_characters, m_length }; }
constexpr char const& operator[](size_t index) const { return m_characters[index]; }
constexpr char const& operator[](size_t index) const
{
if (!is_constant_evaluated())
VERIFY(index < m_length);
return m_characters[index];
}
using ConstIterator = SimpleIterator<const StringView, char const>;