Skip to content

Conversation

hendradarwin
Copy link
Contributor

Problem

When you build the host application located at samples\basic\src\main.c
build the wasm-app located at samples\basic\wasm-apps\testapp.c
and then run the host with wasm app

./basic -f wasm-app/testapp.wasm

you will get an error when calling float_to_string function:

call wasm function float_to_string failed. error: Exception: out of bounds memory access

In my case, I'm compiling the host on Windows, and compiling the wasm-app on Linux.

Solution

After taking a look at the argument array for calling the float_to_string function on the main.c file
I have noticed that the array assignment is not correct.

    argv2[1] = wasm_buffer; // the second argument is the wasm buffer address
    argv2[3] = 1000;         //  the third argument is the wasm buffer size
    argv2[4] = 3; //  the last argument is the digits after decimal point for
                  //  converting float to string

it is supposed to be

    argv2[1] = wasm_buffer; // the second argument is the wasm buffer address
    argv2[2] = 1000;         //  the third argument is the wasm buffer size
    argv2[3] = 3; //  the last argument is the digits after decimal point for
                  //  converting float to string

@TianlongLiang
Copy link
Collaborator

LGTM

@wenyongh wenyongh merged commit 22eef3d into bytecodealliance:main May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants