Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix basic example, parameter mismatch between host and wasm #3415

Merged
merged 1 commit into from
May 13, 2024

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
Contributor

LGTM

@wenyongh wenyongh merged commit 22eef3d into bytecodealliance:main May 13, 2024
369 checks passed
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