diff --git a/Sources/CWasm3/m3_parse.c b/Sources/CWasm3/m3_parse.c index e1bdb7b..d313940 100644 --- a/Sources/CWasm3/m3_parse.c +++ b/Sources/CWasm3/m3_parse.c @@ -228,7 +228,7 @@ _ (ReadLEB_u32 (& index, & i_bytes, i_end)); if (exportKind == d_externalKind_function) { u16 numNames = io_module->functions [index].numNames; - if (numNames < d_m3MaxDuplicateFunctionImpl - 1) + if (numNames < d_m3MaxDuplicateFunctionImpl) { io_module->functions [index].numNames++; io_module->functions [index].names[numNames] = utf8; diff --git a/Tests/CWasm3Tests/CWasm3Tests.swift b/Tests/CWasm3Tests/CWasm3Tests.swift index d202620..f8981b0 100644 --- a/Tests/CWasm3Tests/CWasm3Tests.swift +++ b/Tests/CWasm3Tests/CWasm3Tests.swift @@ -32,7 +32,14 @@ final class CWasm3Tests: XCTestCase { var constant2Function: IM3Function? XCTAssertNil(m3_FindFunction(&constant2Function, runtime, "constant_2")) - [constant1Function, constant2Function] + var constant3Function: IM3Function? + XCTAssertNil(m3_FindFunction(&constant3Function, runtime, "constant_3")) + + var constant4Function: IM3Function? + let err = try XCTUnwrap(m3_FindFunction(&constant4Function, runtime, "constant_4")) + XCTAssertEqual("function lookup failed", String(cString: err)) + + [constant1Function, constant2Function, constant3Function] .forEach { (function) in guard function != nil else { return XCTFail() } let size = UnsafeMutablePointer.allocate(capacity: 1) @@ -292,7 +299,7 @@ extension CWasm3Tests { private func constantWasm() throws -> Array { let base64 = - "AGFzbQEAAAABBQFgAAF/AwIBAAcbAgpjb25zdGFudF8xAAAKY29uc3RhbnRfMgAACggBBgBBgIAECw==" + "AGFzbQEAAAABBQFgAAF/AwIBAAc1BApjb25zdGFudF8xAAAKY29uc3RhbnRfMgAACmNvbnN0YW50XzMAAApjb25zdGFudF80AAAKCAEGAEGAgAQL" guard let data = Data(base64Encoded: base64) else { throw TestError.couldNotDecodeWasm("constant.wasm") } return Array(data) diff --git a/Tests/CWasm3Tests/Resources/constant.wat b/Tests/CWasm3Tests/Resources/constant.wat index b381f56..957b1b9 100644 --- a/Tests/CWasm3Tests/Resources/constant.wat +++ b/Tests/CWasm3Tests/Resources/constant.wat @@ -3,4 +3,6 @@ (func (;0;) (type 0) (result i32) i32.const 65536) (export "constant_1" (func 0)) - (export "constant_2" (func 0))) + (export "constant_2" (func 0)) + (export "constant_3" (func 0)) + (export "constant_4" (func 0)))