From 5f1cf258cce2b3e1559b402a90a596f07ab83ce3 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 6 Sep 2017 19:06:14 +0200 Subject: [PATCH] add edge case for i64.const --- res/cases/v1/const.wasm | Bin 67 -> 89 bytes res/cases/v1/const.wast | 2 ++ src/elements/module.rs | 40 +++++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/res/cases/v1/const.wasm b/res/cases/v1/const.wasm index 6253ea099863dbd49b00ada121a124ab1a5641e1..70cd30789c0caa138c6150f04746d3a080ac571b 100644 GIT binary patch delta 34 ccmZ>coFF3Q!sx`{^dANooEl)Dexign03@;zFaQ7m delta 12 Tcma!ao*=@a$Ed?FQBNBH5$ghq diff --git a/res/cases/v1/const.wast b/res/cases/v1/const.wast index 06ce729..e8f8f1a 100644 --- a/res/cases/v1/const.wast +++ b/res/cases/v1/const.wast @@ -1,6 +1,8 @@ (module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) + i64.const 9223372036854775807 + i64.const -9223372036854775808 i32.const 1024 i32.const 2048 i32.const 4096 diff --git a/src/elements/module.rs b/src/elements/module.rs index c144a8e..66937ce 100644 --- a/src/elements/module.rs +++ b/src/elements/module.rs @@ -22,7 +22,7 @@ impl Default for Module { magic: 0x6d736100, version: 1, sections: Vec::with_capacity(16), - } + } } } @@ -83,7 +83,7 @@ impl Module { for section in self.sections() { if let &Section::Global(ref section) = section { return Some(section); } } - None + None } /// Exports section, if any. @@ -131,7 +131,7 @@ impl Module { for section in self.sections() { if let &Section::Function(ref sect) = section { return Some(sect); } } - None + None } /// Start section, if any. @@ -169,12 +169,12 @@ impl Deserialize for Module { } } - Ok(Module { + Ok(Module { magic: LittleEndian::read_u32(&magic), version: version, sections: sections, }) - } + } } impl Serialize for Module { @@ -249,7 +249,7 @@ mod integration_tests { module_new.import_section().expect("import section exists").entries().len(), "There should be equal amount of import entries before and after serialization" ); - } + } #[test] fn serde_code() { @@ -275,20 +275,22 @@ mod integration_tests { let module = deserialize_file("./res/cases/v1/const.wasm").expect("Should be deserialized"); let func = &module.code_section().expect("Code section to exist").bodies()[0]; - assert_eq!(func.code().elements().len(), 14); + assert_eq!(func.code().elements().len(), 16); - assert_eq!(I32Const(1024), func.code().elements()[0]); - assert_eq!(I32Const(2048), func.code().elements()[1]); - assert_eq!(I32Const(4096), func.code().elements()[2]); - assert_eq!(I32Const(8192), func.code().elements()[3]); - assert_eq!(I32Const(16384), func.code().elements()[4]); - assert_eq!(I32Const(32767), func.code().elements()[5]); - assert_eq!(I32Const(-1024), func.code().elements()[6]); - assert_eq!(I32Const(-2048), func.code().elements()[7]); - assert_eq!(I32Const(-4096), func.code().elements()[8]); - assert_eq!(I32Const(-8192), func.code().elements()[9]); - assert_eq!(I32Const(-16384), func.code().elements()[10]); - assert_eq!(I32Const(-32768), func.code().elements()[11]); + assert_eq!(I64Const(9223372036854775807), func.code().elements()[0]); + assert_eq!(I64Const(-9223372036854775808), func.code().elements()[1]); + assert_eq!(I32Const(1024), func.code().elements()[2]); + assert_eq!(I32Const(2048), func.code().elements()[3]); + assert_eq!(I32Const(4096), func.code().elements()[4]); + assert_eq!(I32Const(8192), func.code().elements()[5]); + assert_eq!(I32Const(16384), func.code().elements()[6]); + assert_eq!(I32Const(32767), func.code().elements()[7]); + assert_eq!(I32Const(-1024), func.code().elements()[8]); + assert_eq!(I32Const(-2048), func.code().elements()[9]); + assert_eq!(I32Const(-4096), func.code().elements()[10]); + assert_eq!(I32Const(-8192), func.code().elements()[11]); + assert_eq!(I32Const(-16384), func.code().elements()[12]); + assert_eq!(I32Const(-32768), func.code().elements()[13]); } #[test]