bgkillas / kalc

a complex numbers, 2d/3d graphing, arbitrary precision, vector/matrix, cli calculator with real-time output and support for units

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pressing 'enter' causes a panic

MarkSwanson opened this issue · comments

Steps to reproduce:

  1. start kalc
  2. press the 'enter' key

$ kalc

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 1', src/parse.rs:23:12
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

On my preliminary glance at the code, it looks like src/main.rs:259 (the read_single_char loop) handles the \n input?
I do not see any error on my machine when using cargo run.

I tried with 'cargo run' and was able to reproduce the error.

Can you run with RUST_BACKTRACE=1 and post the results? In addition, what is your system information? I am WSL2 Ubuntu on Intel Xeon.

Unfortunately, I cannot reproduce it by executing cargo run and then pressing enter. Perhaps I am not performing the correct steps?

thread 'main' panicked at 'attempt to subtract with overflow', src/parse.rs:21:15
stack backtrace:
0: rust_begin_unwind
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/std/src/panicking.rs:593:5
1: core::panicking::panic_fmt
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/panicking.rs:67:14
2: core::panicking::panic
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/panicking.rs:117:5
3: kalc::parse::get_func
at ./src/parse.rs:21:15
4: kalc::print::print_concurrent
at ./src/print.rs:164:15
5: kalc::main
at ./src/main.rs:307:36
6: core::ops::function::FnOnce::call_once
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/ops/function.rs:250:5

Unbuntu 22.04 on an Intel laptop.
You're running the correct steps. Weird...
I did a 'cargo clear' and then cargo run - and I got the same error.

Looking at the code the bug is obvious. chars.len() returns usize so you can't subtract 1 if chars.len() == 0.

This is probably redundant, but are you sure you have the most up-to-date code? Can you run git pull and see if the behavior is fixed?

I was just able to reproduce the error by replacing

if !options.real_time_output {
    frac = print_concurrent(&input, &last, &vars, options, start, end);
}

with

if options.real_time_output {
    frac = print_concurrent(&input, &last, &vars, options, start, end);
}

Did you also do this? Or did you change the Default options?

ah its a bug with disabling real time output, or the --rt option, fixed. thanks for that last comment i would have taken alot longer to figure that out

Thanks all. That was it. I'll include my ~/.config/kalc.config contents in the future.