AK: Use kmalloc_array() where appropriate

This commit is contained in:
Andreas Kling 2021-08-07 22:34:29 +02:00
parent 2189524cb3
commit 3609ac4cf9
Notes: sideshowbarker 2024-07-18 07:17:52 +09:00
2 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ public:
: m_size(size)
{
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)
new (&m_elements[i]) T();
}
@ -34,7 +34,7 @@ public:
: m_size(other.m_size)
{
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)
new (&m_elements[i]) T(other[i]);
}

View file

@ -623,7 +623,7 @@ public:
if (m_capacity >= needed_capacity)
return true;
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)
return false;