mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
5f34c8ab03
commit
13406b83b1
Notes:
sideshowbarker
2024-07-17 08:33:40 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/13406b83b1 Pull-request: https://github.com/SerenityOS/serenity/pull/14696
1 changed files with 6 additions and 1 deletions
|
@ -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>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue