summaryrefslogtreecommitdiff
path: root/Tests/AK/TestHashTable.cpp
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-10 19:54:43 -0600
committerAndrew Kaster <andrewdkaster@gmail.com>2022-11-11 00:44:04 -0700
commita1300d37975c855795fada9eceec99701747c1d6 (patch)
treebc5ba6aee74bcbbb832b71bf157c2d8450ad436b /Tests/AK/TestHashTable.cpp
parent8f0fdef856158b14caea9eb3dc59024989c7817e (diff)
downloadserenity-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 'Tests/AK/TestHashTable.cpp')
-rw-r--r--Tests/AK/TestHashTable.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp
index 410681a352..57a7db0085 100644
--- a/Tests/AK/TestHashTable.cpp
+++ b/Tests/AK/TestHashTable.cpp
@@ -309,3 +309,12 @@ TEST_CASE(reinsertion)
map.remove("__sak");
map.set("__sak");
}
+
+TEST_CASE(clear_with_capacity_when_empty)
+{
+ HashTable<int> map;
+ map.clear_with_capacity();
+ map.set(0);
+ map.set(1);
+ VERIFY(map.size() == 2);
+}