From 87758b27893534d6b7b5c3289dfd83578c7c4ae3 Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Sun, 8 Apr 2018 10:53:14 -0700 Subject: [PATCH] fix memory growing for empty data segments --- src/Language/Wasm/Interpreter.hs | 3 ++- tests/Test.hs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Language/Wasm/Interpreter.hs b/src/Language/Wasm/Interpreter.hs index 6df713e..0c56960 100644 --- a/src/Language/Wasm/Interpreter.hs +++ b/src/Language/Wasm/Interpreter.hs @@ -316,6 +316,7 @@ initialize inst Module {elems, datas, start} store = do return $ st { tableInstances = tableInstances st Vector.// [(idx, table)] } fitOrGrowMemory :: Address -> Store -> Int -> IO MemoryInstance + fitOrGrowMemory idx st 0 = return $ memInstances st ! idx fitOrGrowMemory idx st last = do let m@(MemoryInstance mem maxLen) = memInstances st ! idx let len = IOVector.length mem @@ -329,7 +330,7 @@ initialize inst Module {elems, datas, start} store = do Nothing -> increased Just max -> let maxInBytes = max * pageSize in - if maxInBytes <= last + if maxInBytes < last then error $ "Max memory length reached. Max " ++ show max ++ "(" ++ show maxInBytes ++ "b), but requested " ++ show last else increased diff --git a/tests/Test.hs b/tests/Test.hs index 6d63405..9050d50 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -34,7 +34,7 @@ compile file = do main :: IO () main = do files <- Directory.listDirectory "tests/samples" - -- let files = ["func.wast"] + -- let files = ["memory.wast"] scriptTestCases <- (`mapM` files) $ \file -> do content <- LBS.readFile $ "tests/samples/" ++ file let Right script = Parser.parseScript <$> Lexer.scanner content