From a1300d37975c855795fada9eceec99701747c1d6 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Thu, 10 Nov 2022 19:54:43 -0600 Subject: 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. --- AK/HashTable.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'AK') 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) { for (auto* bucket : *this) bucket->~T(); -- cgit v1.2.3