diff options
author | MacDue <macdue@dueutil.tech> | 2022-07-26 00:38:49 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-26 12:41:46 +0200 |
commit | 13406b83b14db7a674c4ddd79f8089cac031ce92 (patch) | |
tree | 96e86df3e92f033621322cf6ebae123d128fa76f /AK | |
parent | 5f34c8ab03d94977e201adca346540a2c15ede35 (diff) | |
download | serenity-13406b83b14db7a674c4ddd79f8089cac031ce92.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/StringView.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/AK/StringView.h b/AK/StringView.h index 17f0623f8c..f75786bc70 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -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>; |