mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWasm: Make MemoryInstance allocation fail if initial growth fails
...instead of silently ignoring the failure in the constructor.
This commit is contained in:
parent
117ca843bd
commit
4f2d898a51
Notes:
sideshowbarker
2024-07-17 18:42:34 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/4f2d898a51 Pull-request: https://github.com/SerenityOS/serenity/pull/12548 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
2 changed files with 17 additions and 4 deletions
|
@ -43,7 +43,11 @@ Optional<TableAddress> Store::allocate(TableType const& type)
|
|||
Optional<MemoryAddress> Store::allocate(MemoryType const& type)
|
||||
{
|
||||
MemoryAddress address { m_memories.size() };
|
||||
m_memories.empend(MemoryInstance { type });
|
||||
auto instance = MemoryInstance::create(type);
|
||||
if (instance.is_error())
|
||||
return {};
|
||||
|
||||
m_memories.append(instance.release_value());
|
||||
return address;
|
||||
}
|
||||
|
||||
|
|
|
@ -331,10 +331,14 @@ private:
|
|||
|
||||
class MemoryInstance {
|
||||
public:
|
||||
explicit MemoryInstance(MemoryType const& type)
|
||||
: m_type(type)
|
||||
static ErrorOr<MemoryInstance> create(MemoryType const& type)
|
||||
{
|
||||
grow(m_type.limits().min() * Constants::page_size);
|
||||
MemoryInstance instance { type };
|
||||
|
||||
if (!instance.grow(type.limits().min() * Constants::page_size))
|
||||
return Error::from_string_literal("Failed to grow to requested size");
|
||||
|
||||
return { move(instance) };
|
||||
}
|
||||
|
||||
auto& type() const { return m_type; }
|
||||
|
@ -364,6 +368,11 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
explicit MemoryInstance(MemoryType const& type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
MemoryType const& m_type;
|
||||
size_t m_size { 0 };
|
||||
ByteBuffer m_data;
|
||||
|
|
Loading…
Add table
Reference in a new issue