Skip to content

document overflow-checks #675

Open
Open
@ibaryshnikov

Description

@ibaryshnikov

Consider the following code:

#[wasm_bindgen]
pub fn add(a: u8, b: u8) -> u8 {
    a + b
}

The build command is

wasm-pack build --target web

Initialization js is

import init, { add } from './pkg/overflow_check.js';

window.addEventListener('load', async () => {
    await init();

    const result = add(200, 200);
    console.log(`result`, result);
});

Expected result (from JS perspective) is either 400 or error
Actual result is 144
Possible fix is to enable overflow checks in Cargo.toml

[profile.release]
overflow-checks = true

The problem here is that it's a default build, which produces a wrong result silently.

Making debug builds by default was already discussed in #437
I'd like to bring this topic again and collect some feedback here

Environment details:

wasm-pack 0.8.1
wasm-bindgen 0.2.47
rustc 1.36.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions