diff options
author | Zaggy1024 <zaggy1024@gmail.com> | 2022-11-10 19:54:43 -0600 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-11-11 00:44:04 -0700 |
commit | a1300d37975c855795fada9eceec99701747c1d6 (patch) | |
tree | bc5ba6aee74bcbbb832b71bf157c2d8450ad436b /AK | |
parent | 8f0fdef856158b14caea9eb3dc59024989c7817e (diff) | |
download | serenity-a1300d37975c855795fada9eceec99701747c1d6.zip |
AK: Don't crash in HashTable::clear_with_capacity on an empty table
When calling clear_with_capacity on an empty HashTable/HashMap, a null
deref would occur when trying to memset() m_buckets. Checking that it
has capacity before clearing fixes the issue.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/HashTable.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/AK/HashTable.h b/AK/HashTable.h index ad6f7de16e..b2d9b6fe08 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -291,6 +291,8 @@ public: } void clear_with_capacity() { + if (m_capacity == 0) + return; if constexpr (!Detail::IsTriviallyDestructible<T>) { for (auto* bucket : *this) bucket->~T(); |