summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWasm
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-02-15 03:05:49 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-02-16 22:48:32 +0330
commit4f2d898a51ad2276c469f7d00b2353f08c5c4db7 (patch)
treea79ce7d892eb21d07793d358b58b88bd37fd1f32 /Userland/Libraries/LibWasm
parent117ca843bdcd24b81cfcf2833e49b50818660407 (diff)
downloadserenity-4f2d898a51ad2276c469f7d00b2353f08c5c4db7.zip
LibWasm: Make MemoryInstance allocation fail if initial growth fails
...instead of silently ignoring the failure in the constructor.
Diffstat (limited to 'Userland/Libraries/LibWasm')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp6
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h15
2 files changed, 17 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp
index 6893296e29..49d8abc741 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp
+++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp
@@ -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;
}
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h
index d94478e5ef..3278063c12 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h
+++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h
@@ -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;