1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK: Always do bounds checking in Array::operator[]

This commit is contained in:
Andreas Kling 2021-02-27 09:12:44 +01:00
parent b7c66233f6
commit 69d8ad52c4
Notes: sideshowbarker 2024-07-18 21:53:12 +09:00

View file

@ -44,12 +44,12 @@ struct Array {
constexpr const T& at(size_t index) const constexpr const T& at(size_t index) const
{ {
VERIFY(index < size()); VERIFY(index < size());
return (*this)[index]; return __data[index];
} }
constexpr T& at(size_t index) constexpr T& at(size_t index)
{ {
VERIFY(index < size()); VERIFY(index < size());
return (*this)[index]; return __data[index];
} }
constexpr const T& front() const { return at(0); } constexpr const T& front() const { return at(0); }
@ -60,8 +60,8 @@ struct Array {
constexpr bool is_empty() const { return size() == 0; } constexpr bool is_empty() const { return size() == 0; }
constexpr const T& operator[](size_t index) const { return __data[index]; } constexpr const T& operator[](size_t index) const { return at(index); }
constexpr T& operator[](size_t index) { return __data[index]; } constexpr T& operator[](size_t index) { return at(index); }
template<typename T2, size_t Size2> template<typename T2, size_t Size2>
constexpr bool operator==(const Array<T2, Size2>& other) const { return span() == other.span(); } constexpr bool operator==(const Array<T2, Size2>& other) const { return span() == other.span(); }