libluna: Remove make_array() and destroy_array()
Placement new on arrays is a bit unreliable and could cause out-of-bounds data accesses.
This commit is contained in:
parent
b1fb6dee8a
commit
df77fc8de8
@ -754,8 +754,8 @@ Result<u64> ATADevice::read(u8* buf, usize offset, usize size) const
|
||||
ScopedKMutexLock<100> lock(m_drive->channel()->lock());
|
||||
|
||||
// FIXME: Don't always allocate this if we don't need it.
|
||||
auto* temp = TRY(make_array<u8>(block_size));
|
||||
auto guard = make_scope_guard([temp] { delete[] temp; });
|
||||
auto* temp = (u8*)TRY(malloc_impl(block_size));
|
||||
auto guard = make_scope_guard([temp] { free_impl(temp); });
|
||||
|
||||
if (offset % block_size)
|
||||
{
|
||||
|
@ -41,8 +41,8 @@ namespace GPT
|
||||
|
||||
u32 partition_index = 1;
|
||||
|
||||
auto* table = TRY(make_array<PartitionEntry>(header.num_partitions));
|
||||
auto guard = make_scope_guard([table] { delete[] table; });
|
||||
auto* table = (PartitionEntry*)TRY(calloc_impl(header.num_partitions, sizeof(PartitionEntry)));
|
||||
auto guard = make_scope_guard([table] { free_impl(table); });
|
||||
|
||||
nread = TRY(device->read((u8*)table, partition_table_start, sizeof(PartitionEntry) * header.num_partitions));
|
||||
check(nread == sizeof(PartitionEntry) * header.num_partitions);
|
||||
|
@ -91,8 +91,8 @@ namespace Ext2
|
||||
const usize inode_size = m_metadata.size;
|
||||
const usize block_size = m_fs->m_block_size;
|
||||
|
||||
u8* const buf = TRY(make_array<u8>(block_size));
|
||||
auto guard = make_scope_guard([buf] { delete[] buf; });
|
||||
u8* const buf = (u8*)TRY(calloc_impl(block_size, 1));
|
||||
auto guard = make_scope_guard([buf] { free_impl(buf); });
|
||||
|
||||
m_entries.clear();
|
||||
|
||||
|
@ -10,19 +10,7 @@ template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
||||
{
|
||||
T* const result = (T*)TRY(calloc_impl(count, sizeof(T)));
|
||||
new (result) T[count];
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> void destroy(T* item)
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
|
||||
template <typename T> void destroy_array(T* item)
|
||||
{
|
||||
delete[] item;
|
||||
}
|
||||
|
@ -82,12 +82,11 @@ namespace os::FileSystem
|
||||
TRY(stat(path, st, false));
|
||||
if (!S_ISLNK(st.st_mode)) return String {};
|
||||
|
||||
char* buf = TRY(make_array<char>(st.st_size + 1));
|
||||
auto guard = make_scope_guard([buf] { delete[] buf; });
|
||||
char* buf = (char*)TRY(calloc_impl(st.st_size + 1, 1));
|
||||
auto guard = make_scope_guard([buf] { free_impl(buf); });
|
||||
usize nread = TRY(
|
||||
Result<usize>::from_syscall(syscall(SYS_readlinkat, path.dirfd(), path.name().chars(), buf, st.st_size)));
|
||||
|
||||
buf[nread] = '\0';
|
||||
guard.deactivate();
|
||||
|
||||
return String { buf, nread };
|
||||
|
Loading…
Reference in New Issue
Block a user