Archived
fix: memory.grow by a negative number is an error (#498)
This is to comply with e.g. wasmtime. The spec does not make it explicit what growing by a negative number should mean. It's likely a mistake, so let's fail. Closes #442.
This commit is contained in:
+16
-10
@@ -708,18 +708,24 @@ d_m3Op (MemGrow)
|
||||
IM3Runtime runtime = m3MemRuntime(_mem);
|
||||
IM3Memory memory = & runtime->memory;
|
||||
|
||||
u32 numPagesToGrow = (u32) _r0;
|
||||
_r0 = memory->numPages;
|
||||
i32 numPagesToGrow = _r0;
|
||||
if (numPagesToGrow >= 0) {
|
||||
_r0 = memory->numPages;
|
||||
|
||||
if (M3_LIKELY(numPagesToGrow))
|
||||
if (M3_LIKELY(numPagesToGrow))
|
||||
{
|
||||
u32 requiredPages = memory->numPages + numPagesToGrow;
|
||||
|
||||
M3Result r = ResizeMemory (runtime, requiredPages);
|
||||
if (r)
|
||||
_r0 = -1;
|
||||
|
||||
_mem = memory->mallocated;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 requiredPages = memory->numPages + numPagesToGrow;
|
||||
|
||||
M3Result r = ResizeMemory (runtime, requiredPages);
|
||||
if (r)
|
||||
_r0 = -1;
|
||||
|
||||
_mem = memory->mallocated;
|
||||
_r0 = -1;
|
||||
}
|
||||
|
||||
nextOp ();
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
(module
|
||||
(func $to_test (result i32)
|
||||
i32.const -1
|
||||
memory.grow)
|
||||
(memory 1 5)
|
||||
(export "to_test" (func $to_test))
|
||||
)
|
||||
Reference in New Issue
Block a user