erhanbaris / smartcalc

Text based calculator for peoples
https://erhanbaris.github.io/smartcalc-app/
GNU General Public License v2.0
189 stars 7 forks source link

panic when evaluating `=` (variable assignment without name) #26

Closed superhawk610 closed 2 years ago

superhawk610 commented 2 years ago

Reproduction

#[test]
fn execute_empty_assignment() {
    let calc = SmartCalc::default();
    calc.execute("en".to_string(), r"=".to_string());
}

Expected Behaviour

No panic, just return an error (variable assignment requires variable name).

Actual Behaviour

smartcalc = "1.0.6"

Panic with the following backtrace

thread 'tests::executer_test::execute_empty_assignment' panicked at 'attempt to subtract with overflow', src/variable/mod.rs:44:72
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:48:5
   3: smartcalc::variable::update_token_variables
             at ./src/variable/mod.rs:44:72
   4: smartcalc::tokinizer::Tokinizer::tokinize
             at ./src/tokinizer/mod.rs:124:9
   5: smartcalc::app::SmartCalc::execute_text
             at ./src/app.rs:169:13
   6: smartcalc::app::SmartCalc::execute_session
             at ./src/app.rs:210:35
   7: smartcalc::app::SmartCalc::execute
             at ./src/app.rs:201:9
   8: smartcalc::tests::executer_test::execute_empty_assignment
             at ./src/tests/executer_test.rs:722:5
   9: smartcalc::tests::executer_test::execute_empty_assignment::{{closure}}
             at ./src/tests/executer_test.rs:720:1
  10: core::ops::function::FnOnce::call_once
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
  11: core::ops::function::FnOnce::call_once
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
erhanbaris commented 2 years ago

Issue fixed at v1.0.7 release