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

panic on division by zero #780

Closed
alexanderkjall opened this issue Oct 3, 2020 · 3 comments · Fixed by #790 or #882
Closed

panic on division by zero #780

alexanderkjall opened this issue Oct 3, 2020 · 3 comments · Fixed by #790 or #882
Labels
bug Something isn't working

Comments

@alexanderkjall
Copy link

Describe the bug

Expected an Error, not a panic.

To Reproduce

Can be reproduced with this program:

fn main() {
    let mut context = boa::Context::new();
    let _ = context.eval("1n/0n");
}

Expected behavior

An Error

Build environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Version: 0.10.0
  • Target triple: [e.g. x86_64-unknown-linux-gnu]
  • Rustc version: 1.48.0-nightly (d006f5734 2020-08-28)

Additional context

Stacktrace:

thread 'main' panicked at 'attempt to divide by zero', /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/algorithms.rs:600:9
stack backtrace:
   0: std::panicking::begin_panic
             at /home/capitol/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:505
   1: num_bigint::biguint::algorithms::div_rem_ref
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/algorithms.rs:600
   2: <num_bigint::biguint::BigUint as num_integer::Integer>::div_rem
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/biguint.rs:1492
   3: <num_bigint::bigint::BigInt as num_integer::Integer>::div_rem
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/bigint.rs:2222
   4: <&num_bigint::bigint::BigInt as core::ops::arith::Div<&num_bigint::bigint::BigInt>>::div
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/bigint.rs:1716
   5: <num_bigint::bigint::BigInt as core::ops::arith::DivAssign<&num_bigint::bigint::BigInt>>::div_assign
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/bigint.rs:1724
   6: <num_bigint::bigint::BigInt as core::ops::arith::DivAssign>::div_assign
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/macros.rs:114
   7: boa::builtins::bigint::operations::<impl core::ops::arith::Div for boa::builtins::bigint::BigInt>::div
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/builtins/bigint/operations.rs:42
   8: boa::value::operations::<impl boa::value::Value>::div
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/value/operations.rs:109
   9: boa::exec::operator::<impl boa::exec::Executable for boa::syntax::ast::node::operator::BinOp>::run
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/operator/mod.rs:62
  10: <boa::syntax::ast::node::Node as boa::exec::Executable>::run
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/mod.rs:107
  11: boa::exec::statement_list::<impl boa::exec::Executable for boa::syntax::ast::node::statement_list::StatementList>::run
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/statement_list.rs:17
  12: boa::context::Context::eval
             at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/Boa-0.10.0/src/context.rs:494
  13: boa_reproduce::main
             at ./src/main.rs:3
  14: core::ops::function::FnOnce::call_once
             at /home/capitol/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
@Razican
Copy link
Member

Razican commented Oct 8, 2020

This seems to still be happening with the % (modulo) operator, I'm re-opening the issue.

@Razican Razican reopened this Oct 8, 2020
@Razican Razican mentioned this issue Oct 8, 2020
@croraf
Copy link
Contributor

croraf commented Oct 14, 2020

@Razican Can you show the examples which produce the wrong result and that should work after this is fixed?

@Razican
Copy link
Member

Razican commented Oct 16, 2020

@Razican Can you show the examples which produce the wrong result and that should work after this is fixed?

Yep, for example this:

let a = 10 % 0;
a;

Panics, saying it entered unreachable code. It should return a NaN instead. This was solved for the division (/) operator, but not for the modulo (%) operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants