mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Fix FixedArray zero bytes allocations
This commit is contained in:
parent
f5bc7dbfda
commit
80560d1be3
Notes:
sideshowbarker
2024-07-19 02:59:56 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/80560d1be31 Pull-request: https://github.com/SerenityOS/serenity/pull/3355
1 changed files with 14 additions and 6 deletions
|
@ -38,10 +38,12 @@ public:
|
|||
explicit FixedArray(size_t size)
|
||||
: m_size(size)
|
||||
{
|
||||
if (m_size != 0) {
|
||||
m_elements = (T*)kmalloc(sizeof(T) * m_size);
|
||||
for (size_t i = 0; i < m_size; ++i)
|
||||
new (&m_elements[i]) T();
|
||||
}
|
||||
}
|
||||
~FixedArray()
|
||||
{
|
||||
clear();
|
||||
|
@ -50,10 +52,12 @@ public:
|
|||
FixedArray(const FixedArray& other)
|
||||
: m_size(other.m_size)
|
||||
{
|
||||
if (m_size != 0) {
|
||||
m_elements = (T*)kmalloc(sizeof(T) * m_size);
|
||||
for (size_t i = 0; i < m_size; ++i)
|
||||
new (&m_elements[i]) T(other[i]);
|
||||
}
|
||||
}
|
||||
|
||||
FixedArray& operator=(const FixedArray& other)
|
||||
{
|
||||
|
@ -106,6 +110,10 @@ public:
|
|||
{
|
||||
if (new_size == m_size)
|
||||
return;
|
||||
if (new_size == 0) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
auto* new_elements = (T*)kmalloc(new_size * sizeof(T));
|
||||
for (size_t i = 0; i < min(new_size, m_size); ++i)
|
||||
new (&new_elements[i]) T(move(m_elements[i]));
|
||||
|
|
Loading…
Reference in a new issue