AK+Kernel+Userland: Don't allow Vector::resize() in the kernel

This function doesn't propagate allocation failures.

Replace all current usages of this function by using `try_resize()`
instead.
This commit is contained in:
Sönke Holz authored and Sönke Holz committed 2025-11-22 19:51:20 +01:00
1 parent 5542998a79
commit fbb63faa1d
8 files changed
+10 -8

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@ requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); })
{
auto prepare_kmp_partial_table = [&] {
Vector<int, 64> table;
table.resize(needle.size());
table.try_resize(needle.size()).release_value_but_fixme_should_propagate_errors();
size_t position = 1;
int candidate = 0;
+2
View File
@@ -782,11 +782,13 @@ public:
m_size = new_size;
}
#ifndef KERNEL
void resize(size_t new_size, bool keep_capacity = false)
requires(!contains_reference)
{
MUST(try_resize(new_size, keep_capacity));
}
#endif
void resize_and_keep_capacity(size_t new_size)
requires(!contains_reference)
+2 -2
View File
@@ -360,7 +360,7 @@ UNMAP_AFTER_INIT void APIC::setup_ap_boot_environment()
}
// Allocate Processor structures for all APs and store the pointer to the data
m_ap_processor_info.resize(aps_to_enable);
m_ap_processor_info.try_resize(aps_to_enable).release_value_but_fixme_should_propagate_errors();
for (size_t i = 0; i < aps_to_enable; i++)
m_ap_processor_info[i] = adopt_nonnull_own_or_enomem(new (nothrow) Processor()).release_value_but_fixme_should_propagate_errors();
auto* ap_processor_info_array = &ap_stack_array[aps_to_enable];
@@ -399,7 +399,7 @@ UNMAP_AFTER_INIT void APIC::do_boot_aps()
// because we won't be able to send FlushTLB messages, so we have to
// have all memory set up for the threads so that when the APs are
// starting up, they can access all the memory properly
m_ap_idle_threads.resize(aps_to_enable);
m_ap_idle_threads.try_resize(aps_to_enable).release_value_but_fixme_should_propagate_errors();
for (u32 i = 0; i < aps_to_enable; i++)
m_ap_idle_threads[i] = Scheduler::create_ap_idle_thread(i + 1);
+1 -1
View File
@@ -152,7 +152,7 @@ UNMAP_AFTER_INIT ErrorOr<void> UHCIController::create_structures()
m_isochronous_transfer_pool = TRY(MM.allocate_dma_buffer_page("UHCI Isochronous Descriptor Pool"sv, Memory::Region::Access::ReadWrite, Memory::MemoryType::IO));
// Set up the Isochronous Transfer Descriptor list
m_iso_td_list.resize(UHCI_NUMBER_OF_ISOCHRONOUS_TDS);
TRY(m_iso_td_list.try_resize(UHCI_NUMBER_OF_ISOCHRONOUS_TDS));
for (size_t i = 0; i < m_iso_td_list.size(); i++) {
auto placement_addr = reinterpret_cast<void*>(m_isochronous_transfer_pool->vaddr().get() + (i * sizeof(Kernel::USB::TransferDescriptor)));
auto paddr = static_cast<u32>(m_isochronous_transfer_pool->physical_page(0)->paddr().get() + (i * sizeof(Kernel::USB::TransferDescriptor)));
+1 -1
View File
@@ -44,7 +44,7 @@ UNMAP_AFTER_INIT ErrorOr<void> Console::initialize_virtio_resources()
}
if (is_feature_accepted(VIRTIO_CONSOLE_F_MULTIPORT)) {
max_nr_ports = transport_entity().config_read32(*cfg, 0x4);
m_ports.resize(max_nr_ports);
m_ports.try_resize(max_nr_ports).release_value_but_fixme_should_propagate_errors();
}
});
dbgln("VirtIO::Console: cols: {}, rows: {}, max nr ports {}", cols, rows, max_nr_ports);
+1 -1
View File
@@ -155,7 +155,7 @@ void ConsoleImpl::set_size(u16 determined_columns, u16 determined_rows)
m_normal_saved_state.cursor.clamp(rows() - 1, columns() - 1);
m_alternate_saved_state.cursor.clamp(rows() - 1, columns() - 1);
m_saved_cursor_position.clamp(rows() - 1, columns() - 1);
m_horizontal_tabs.resize(determined_columns);
m_horizontal_tabs.try_resize(determined_columns).release_value_but_fixme_should_propagate_errors();
for (unsigned i = 0; i < determined_columns; ++i)
m_horizontal_tabs[i] = (i % 8) == 0;
// Rightmost column is always last tab on line.
@@ -56,7 +56,7 @@ public:
BigEndian<FlatPtr> big_endian_flatptr { flatptr };
Address address;
address.m_raw.resize(sizeof(FlatPtr));
address.m_raw.try_resize(sizeof(FlatPtr)).release_value_but_fixme_should_propagate_errors();
__builtin_memcpy(address.m_raw.data(), &big_endian_flatptr, sizeof(big_endian_flatptr));
return address;
}
+1 -1
View File
@@ -35,7 +35,7 @@ void Line::rewrap(size_t new_length, Line* next_line, CursorPosition* cursor, bo
void Line::set_length(size_t new_length)
{
m_cells.resize(new_length);
m_cells.try_resize(new_length).release_value_but_fixme_should_propagate_errors();
if (m_terminated_at.has_value())
m_terminated_at = min(*m_terminated_at, new_length);
}