1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

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.
This commit is contained in:
Zaggy1024 2022-11-10 19:54:43 -06:00 committed by Andrew Kaster
parent 8f0fdef856
commit a1300d3797
2 changed files with 11 additions and 0 deletions

View file

@ -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();