Browse Source

AK: Use kmalloc_array() where appropriate

Andreas Kling 3 năm trước cách đây
mục cha
commit
3609ac4cf9
2 tập tin đã thay đổi với 3 bổ sung3 xóa
  1. 2 2
      AK/FixedArray.h
  2. 1 1
      AK/Vector.h

+ 2 - 2
AK/FixedArray.h

@@ -20,7 +20,7 @@ public:
         : m_size(size)
         : m_size(size)
     {
     {
         if (m_size != 0) {
         if (m_size != 0) {
-            m_elements = (T*)kmalloc(sizeof(T) * m_size);
+            m_elements = static_cast<T*>(kmalloc_array(m_size, sizeof(T)));
             for (size_t i = 0; i < m_size; ++i)
             for (size_t i = 0; i < m_size; ++i)
                 new (&m_elements[i]) T();
                 new (&m_elements[i]) T();
         }
         }
@@ -34,7 +34,7 @@ public:
         : m_size(other.m_size)
         : m_size(other.m_size)
     {
     {
         if (m_size != 0) {
         if (m_size != 0) {
-            m_elements = (T*)kmalloc(sizeof(T) * m_size);
+            m_elements = static_cast<T*>(kmalloc_array(m_size, sizeof(T)));
             for (size_t i = 0; i < m_size; ++i)
             for (size_t i = 0; i < m_size; ++i)
                 new (&m_elements[i]) T(other[i]);
                 new (&m_elements[i]) T(other[i]);
         }
         }

+ 1 - 1
AK/Vector.h

@@ -623,7 +623,7 @@ public:
         if (m_capacity >= needed_capacity)
         if (m_capacity >= needed_capacity)
             return true;
             return true;
         size_t new_capacity = kmalloc_good_size(needed_capacity * sizeof(StorageType)) / sizeof(StorageType);
         size_t new_capacity = kmalloc_good_size(needed_capacity * sizeof(StorageType)) / sizeof(StorageType);
-        auto* new_buffer = (StorageType*)kmalloc(new_capacity * sizeof(StorageType));
+        auto* new_buffer = static_cast<StorageType*>(kmalloc_array(new_capacity, sizeof(StorageType)));
         if (new_buffer == nullptr)
         if (new_buffer == nullptr)
             return false;
             return false;