a8m / pb

Console progress bar for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic when tick called on 0 sized progress bar

exrook opened this issue · comments

commented

Issue

Progress bar panics when tick is called on a progress bar with a size of 0

Source

extern crate pbr;

use pbr::ProgressBar;

fn main() {
    let mut pb = ProgressBar::new(0);
    pb.tick();
}

Output

$ RUST_BACKTRACE=1 cargo run
     Running `target/debug/simple`
thread 'main' panicked at 'attempted to subtract with overflow', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/pbr-0.2.1/src/pb.rs:300
stack backtrace:
   1:     0x5632b2488454 - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
   2:     0x5632b248a91b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
   3:     0x5632b248a59f - std::panicking::default_hook::he0146e6a74621cb4
   4:     0x5632b248250e - std::panicking::rust_panic_with_hook::h587239a80cad02d2
   5:     0x5632b248abb1 - std::panicking::begin_panic::h77cefecf7d758cdf
   6:     0x5632b2482e4a - std::panicking::begin_panic_fmt::hb3024643f3039337
   7:     0x5632b248ab41 - rust_begin_unwind
   8:     0x5632b24c009f - core::panicking::panic_fmt::h5594591d20dedfcd
   9:     0x5632b24c0378 - core::panicking::panic::hd4053e15e2373559
  10:     0x5632b247c4f9 - pbr::pb::ProgressBar::draw::hd3bda774ee48668f
                        at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/pbr-0.2.1/src/pb.rs:300
  11:     0x5632b2478cb7 - pbr::pb::ProgressBar::tick::h90f6a1e14ec41113
                        at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/pbr-0.2.1/src/pb.rs:213
  12:     0x5632b247d095 - pbr::pb::ProgressBar::add::he01eca6677e26851
                        at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/pbr-0.2.1/src/pb.rs:230
  13:     0x5632b24703d5 - simple::main::h8834ccd5a1286944
                        at src/main.rs:7
  14:     0x5632b248a1d8 - std::panicking::try::call::hd0906b54b9bfbb20
  15:     0x5632b24942ab - __rust_try
  16:     0x5632b249424e - __rust_maybe_catch_panic
  17:     0x5632b2489c0c - std::rt::lang_start::hfe4efe1fc39e4a30
  18:     0x5632b2470c89 - main
  19:     0x7f5ca06cc740 - __libc_start_main
  20:     0x5632b2470288 - _start
  21:                0x0 - <unknown>
error: Process didn't exit successfully: `target/debug/simple` (exit code: 101)

Norepro:

$ cargo run --example test
     Running `P:\Rust\pb\target\debug\examples\test.exe`
0 / 0  NaN % 0.00/s
$ echo $?
0